Django Template Variables and Javascript

后端 未结 15 2698
误落风尘
误落风尘 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条回答
  •  眼角桃花
    2020-11-22 06:24

    There is a nice easy way implemented from Django 2.1+ using a built in template tag json_script. A quick example would be:

    Declare your variable in your template:

    {{ variable|json_script:'name' }}

    And then call the variable in your

提交回复
热议问题