Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138221

Right way to escape JSON data from django template

$
0
0

I want to pass a dictionary from django view to a javascript file. The dictionary is built from a database populated by site users. What's the difference between these 2 methods in terms of security?

  1. var mydata = JSON.parse("{{mydata|escapejs}}");

  2. var mydata = {{ mydata|safe }};

Further, the doc at django says this for escapejs : This does not make the string safe for use in HTML. Could you show me an example of how it's unsafe & how can I make it safe.


Viewing all articles
Browse latest Browse all 138221

Trending Articles