JS如何使用Django模板中的变量

      JS如何使用Django模板中的变量已关闭评论

django中传递到页面中的并不是变量, 是文本的替换

http://stackoverflow.com/questions/298772/django-template-variables-and-javascript上下面这句话解释的很清楚。

The {{variable}} is substituted directly into the HTML. Do a view source; it isn’t a “variable” or anything like it. It’s just text.

Having said that, you can put this kind of substitution into your javascript

<script type="text/javascript"> 
var a = "{{someDjangoVariable}}"
</script>

gives you “dynamic” javascript

版权声明:本文为博主原创文章,未经博主允