how to display JSON data in template

794 views
Skip to first unread message

aysh...@gmail.com

unread,
Jun 27, 2016, 1:41:10 PM6/27/16
to Django users
Greetings,

How can I access and display JSON data in a template html file? I am getting the JSON data back in the javascript console as follows : 

I tried {{ jason_data }} but no luck.

Thank you!

Here is how I am returning the json data in views.py:
return HttpResponse(json_obj, content_type='application/json')

  1. Console: 
  2. [ObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObjectObject]
    1. 0:Object
    2. 1:Object
    3. 2:Object
    4. 3:Object
    5. 4:Object
    6. 5:Object
    7. 6:Object
    8. 7:Object
    9. 8:Object
    10. 9:Object
    11. 10:Object
    12. 11:Object
    13. 12:Object
    14. 13:Object
    15. length:14
    16. __proto__:Array[0]

Stephen J. Butler

unread,
Jun 27, 2016, 1:45:37 PM6/27/16
to django...@googlegroups.com
Your json_obj is just a collection of python data structures (dictionaries, arrays, strings, ints, etc)... it isn't JSON. You need to serialize it to a string first using DjangoJSONEncoder. 


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5742de2f-67d8-4553-bb78-25b6a9dbf9a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages