列表变量包含字符串未在Django模板中呈现 [英] List variable containing string not getting rendered in Django Template

查看:88
本文介绍了列表变量包含字符串未在Django模板中呈现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名字列表,我在一个地方的HTML中的两个不同的地方渲染,它的工作正常,另一个时间消失。

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆