如何在javascript中使用django变量

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/WitsMakeMen/article/details/28880121

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

展开阅读全文

没有更多推荐了,返回首页