列表变量包含字符串未在Django模板中呈现 [英] List variable containing string not getting rendered in Django Template
本文介绍了列表变量包含字符串未在Django模板中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
names = ['a','b','c','d']
在我打印的HTML代码中
{{names}}
这给了我正确的结果。当我在javascript中使用相同的字符串时,它会停止工作,但是如果我用
['a','b ','c','d']
然后它工作正常。
解决方案
你在javascript中是什么意思?是否在Django中呈现模板,如果不是您希望对其进行评估?
I have a list of names, which I render at two different places in a HTML at one place it works fine, the other time it disappears.
names= ['a','b','c','d']
In the HTML code I am printing
{{names}}
this gives me the correct results. When I use the same string in a javascript it stops working but if I replace the variable by
['a','b','c','d']
then it works fine.
解决方案
What do you mean 'in a javascript'? Is that in a template being rendered by Django, and if not how are you expecting it to be evaluated?
这篇关于列表变量包含字符串未在Django模板中呈现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文