在Django网址模板标记中获取javascript变量的值 [英] Get javascript variable's value in Django url template tag
本文介绍了在Django网址模板标记中获取javascript变量的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
据了解,使用django模板标签url可以使用DRY方式指向一个URL,例如
It is known that there's a DRY way of directing to an URL by using django template tag "url", say
{% url "someview" arg1=X %}
在这里,我想要X一个javascript变量的值,例如 tmp
。但是以下内容不起作用。
Here, I want "X" to be the value of a javascript variable, say tmp
. But the following doesn't work
<script>
...{% url "someview" arg1=tmp %}...
</script>
如何获取模板标签中的值?
How should I get the value inside a template tag?
推荐答案
我发现一个可能在大多数情况下工作的技巧:
I found a trick that might work under most circumstances:
var url_mask = "{% url 'someview' arg1=12345 %}".replace(/12345/, tmp.toString());
它干净,不会打破DRY原则。
It's clean, and it doesn't break DRY principle.
这篇关于在Django网址模板标记中获取javascript变量的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文