Django: passing JSON from view to template

后端 未结 3 610
滥情空心
滥情空心 2020-12-16 00:24

In views.py, I have time series data stored in a dictionary as follows:

time_series = {\"timestamp1\": occurrences, \"timestamp2\": occurrences}         


        
3条回答
  •  执笔经年
    2020-12-16 01:00

    If a frontend library needs a to parse JSON, you can use the json library to convert a python dict to a JSON valid string. Use the escapejs filter

    import json
    
    def foo(request):
        json_string = json.dumps()
        render(request, "foo.html", {'time_series_json_string': json_string})
    
    
    
    

提交回复
热议问题