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 - Javascript gets all messed up with trying to parse the object because of the nomenclature [ > Object:ID <, > Object:ID <,... ]
Django View
django_list = list(Some_Object.objects.all())
Template HTML + JS
<script type="text/javascript" >
var js_list = {{django_list}};
</script>
2. JSON Approach - Django fails on converting the object list to a json string
is not JSON serializable
Django View
django_list = list(Some_Object.objects.all())
json_list = simplejson.dumps(django_list)
Template HTML + JS
<script type="text/javascript" >
var js_list = {{json_list}};
</script>
So, I need some help here :)
Any one has any suggestion / solution?
Thanks!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…