Django Template Variables and Javascript

后端 未结 15 2764
误落风尘
误落风尘 2020-11-22 05:59

When I render a page using the Django template renderer, I can pass in a dictionary variable containing various values to manipulate them in the page using {{ myVar }}

15条回答
  •  闹比i
    闹比i (楼主)
    2020-11-22 06:18

    Here is what I'm doing very easily: I modified my base.html file for my template and put that at the bottom:

    {% if DJdata %}
        
    {% endif %}
    

    then when I want to use a variable in the javascript files, I create a DJdata dictionary and I add it to the context by a json : context['DJdata'] = json.dumps(DJdata)

    Hope it helps!

提交回复
热议问题