如何将我的上下文变量传递给Django中的一个javascript文件? [英] How can I pass my context variables to a javascript file in Django?
本文介绍了如何将我的上下文变量传递给Django中的一个javascript文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这个问题必须很明显,但我无法弄清楚。
This question must be obvious but I can't figure it out.
在一个模板中,我链接到我的媒体目录中的一个js文件。从该文件,我想访问一个上下文变量,如{{my_chart}}。
In a template, I link to a js file in my media directory. From that file, I would like to access a context variable like {{my_chart}}.
但语法不同?谢谢!!
But is the syntax different?? Thank you!!
推荐答案
我不认为这是可能的。如果要访问视图提供的一些数据,则必须将其传递给js函数。
I don't think it's possible this way. If you want to access some data provided by the view, you have to pass it to the js function.
示例
js文件:
my_cool_js_function(some_param){
// do some cool stuff
}
查看
// some html code
my_cool_js_function({{param}})
希望这有助于:)
这篇关于如何将我的上下文变量传递给Django中的一个javascript文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文