0
我有一個函數,我將其傳遞給views.py中的上下文,並在django模板中用於在javascript圖表中使用。Django:生成字符串列表
功能:
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"],
如何獲得正確的字符串?任何幫助深表感謝!
我使用Python 3.5和Django 1.10。