在django中使用python格式化字符串

时间:2023-01-27 20:25:40

I have a question list for a questionnaire which are stored in database but some questions has to be modified by certain parameters.

我有一个问卷清单,存储在数据库中,但有些问题必须通过某些参数进行修改。

For example, if someone selects an employer name from previous page, some questions should have employer's name "Do you like to work for ........ company ?".

例如,如果有人从上一页选择雇主姓名,那么一些问题应该有雇主的名字“你喜欢为........公司工作吗?”。

One solution might be savinf question like "Do you like to work for {0}" and formatting it but I am not sure how I can implement it with python.

一个解决方案可能是savinf问题,如“你喜欢为{0}工作”并格式化它,但我不知道如何用python实现它。

But how can I detect which questions need to be modified ?

但是,如何检测需要修改哪些问题?

Is there any easy way to do it in django ?

在django有没有简单的方法呢?

Thanks

1 个解决方案

#1


1  

The most flexible way - is to create custom template filter. If string needs formatting, it will do that, if it doesn't - just output it.

最灵活的方式 - 创建自定义模板过滤器。如果字符串需要格式化,它会这样做,如果不需要 - 只输出它。

#1


1  

The most flexible way - is to create custom template filter. If string needs formatting, it will do that, if it doesn't - just output it.

最灵活的方式 - 创建自定义模板过滤器。如果字符串需要格式化,它会这样做,如果不需要 - 只输出它。