How can I pass my context variables to a javascript file in Django?

前端 未结 3 2021
庸人自扰
庸人自扰 2020-12-02 14:50

This question must be obvious but I can\'t figure it out.

In a template, I link to a js file in my media directory. From that file, I would like to access a context

3条回答
  •  萌比男神i
    2020-12-02 15:01

    In addition to Andrzej Bobak's answer, you can also generate a global variable in Javascript from your template. For example, your template might generate code like this:

    
    

    Your script could then refer to my_chart.

提交回复
热议问题