如何在html< script>中使用django变量标签? [英] How to use use a django variable in html <script> tag?

查看:56
本文介绍了如何在html< script>中使用django变量标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像python变量具有值列表一样,我想将变量等同,例如var list =标记内的python变量.

Like the python variable has a list of values and I want to equate a variable, say var list= python variable inside tag.

推荐答案

Django中的变量标签被 {{{}} 包围,并被替换为值评估模板时.话虽如此,您可以按照以下方式使用JavaScript中的Django变量:

Variable tags in Django are surrounded by {{ and }}and they're replaced with values when the template is evaluated. That being said, you can make use of the Django variables in JavaScript as follow:

<script type="text/javascript"> 
   var list = "{{djangoVariable}}"
</script>

这篇关于如何在html&lt; script&gt;中使用django变量标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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