Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Django:生成字符串列表_Python_Django - Fatal编程技术网

Python Django:生成字符串列表

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 "

我有一个传递到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 "  + 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转义。当“自动转义”处于禁用状态时,此过滤器无效