Passing objects from Django to Javascript DOM

前端 未结 14 1129
野的像风
野的像风 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:20

    Consolidated answer (my env: Django 2.0)

    In views.py

    import json
    data= []
    // fil the list
    context['mydata'] = json.dumps({'data':data})
    

    In template

      
    

提交回复
热议问题