Passing objects from Django to Javascript DOM

前端 未结 14 1127
野的像风
野的像风 2020-12-04 21:26

I\'m trying to pass a Query Set from Django to a template with javascript.

I\'ve tried different approaches to solve this:

1. Normal Approach - Javas

14条回答
  •  既然无缘
    2020-12-04 22:02

    You can use the combination of safe and escapejs built-in filter in Django.

    var json_string = unescape({{json_list | safe | escapejs}});
    var json_data = JSON.parse(json_string);
    

提交回复
热议问题