[英]using Django Template Variables in javascript
I'm writing an app that needs dynamic javascript. 我正在写一个需要动态JavaScript的应用程序。 I didn't know how to use Django template variable in javascript.
我不知道如何在javascript中使用Django模板变量。 when I searched I found some answeres like Django Template Variables and Javascript but I still have the problem.
当我搜索时,我发现了一些答案,例如Django模板变量和Javascript,但仍然存在问题。 when I write this piece of code in my html :
当我在html中编写这段代码时:
<script>jQuery(document).ready(function ($) {
$(".nav").css({"opacity": "0.5"});
$("#description").animate({opacity: '+=0.5'}, 10000);
});
</script>
every thing is fine. 一切顺利。 the navbar is transparent and
<p id="description">{{description}}</p>
is shown by jquery animate function. 导航栏是透明的,并且
<p id="description">{{description}}</p>
由jquery animate函数显示。 but when i change it to this: 但是当我将其更改为此:
<script>jQuery(document).ready(function ($) {
$(".nav").css({"opacity": "0.5"});
var a = "{{description}}";
$("#description").animate({opacity: '+=0.5'}, 10000);
});
</script>
the navbar is no more transparent and the description is no more shown. 导航栏不再透明,不再显示说明。 what is the problem ?
问题是什么 ?
ps : I changed a to a = "{{blah}}"; ps:我将a更改为=“ {{blah}}”; and there is no problem with it.
并没有问题。 the problem apears when It is a real template variable.
当它是一个真实的模板变量时,问题就解决了。
Stops the template engine from rendering the contents of this block tag.
阻止模板引擎呈现此block标记的内容。
A common use is to allow a JavaScript template layer that collides with Django's syntax.
通常的用途是允许JavaScript模板层与Django的语法冲突。 For example:
例如:
{% verbatim %} {{if dying}}Still alive.{{/if}} {% endverbatim %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.