Django Template Variables and Javascript

后端 未结 15 2359
误落风尘
误落风尘 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

    I use this way in Django 2.1 and work for me and this way is secure (reference):

    Django side:

    def age(request):
        mydata = {'age':12}
        return render(request, 'test.html', context={"mydata_json": json.dumps(mydata)})
    

    Html side:

    
    

提交回复
热议问题