且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将我的上下文变量传递给 Django 中的 javascript 文件?

更新时间:2023-01-13 12:19:01

我认为这种方式是不可能的.如果要访问视图提供的某些数据,必须将其传递给 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}})

希望这有帮助:)