在外部JavaScript中使用django模板标签 [英] using django template tags inside external JavaScript
本文介绍了在外部JavaScript中使用django模板标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
解决方案
只有您将像模板一样解析JS。
如果您需要JS中的某些变量(如 STATIC_URL
),可以使用
< script> window.staticUrl ={{STATIC_URL}}< / script>
或
< html data-static-url ={{STATIC_URL}}>
在您的基本模板中
i have included a js file(eg:application.js) inside my html page but i couldn't able to use django template tag inside that js file ,is there any way to use django template tag directly inside external js file?
解决方案
Only if you will parse JS like a template.
If you need some variable inside JS (like STATIC_URL
), it is ok to use
<script>window.staticUrl = "{{ STATIC_URL }}"</script>
or
<html data-static-url="{{ STATIC_URL }}">
in your base template
这篇关于在外部JavaScript中使用django模板标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文