Python Django:生成字符串列表
我有一个传递到views.py中的上下文的函数,并在django模板中使用,以便在javascript图表中使用 功能:Python Django:生成字符串列表,python,django,Python,Django,我有一个传递到views.py中的上下文的函数,并在django模板中使用,以便在javascript图表中使用 功能: def cleaning_data_plotly(area_id): _input = pricecleaning.values('percent_of_obs','price_cleaning',) data = [] for row in _input: data.append(str("Price of cleaning is "
def cleaning_data_plotly(area_id):
_input = pricecleaning.values('percent_of_obs','price_cleaning',)
data = []
for row in _input:
data.append(str("Price of cleaning is " + str(row['price_cleaning']) + " USD in " + str(percent_of_obs)+" % of cases"))
return data
模板:
text: {{ price_cleaning }},
当我检查输出时,我看到:
text: ['Price of cleaning is 68 USD in 3.58 % of cases ', 'Price of cleaning is 78 USD in 7.58 % of cases '],
鉴于我的预期:
text: ["Price of cleaning is 68 USD in 3.58 % of cases", "Price of cleaning is 78 USD in 7.58 % of cases"],
如何获得正确的字符串?非常感谢您的帮助
我使用的是Python3.5和Django 1.10。Add | safe,如果您不想看到这样转义的引号
{{ price_cleaning | safe }}
将字符串标记为在输出之前不需要进一步的HTML转义。当“自动转义”处于禁用状态时,此过滤器无效