Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to remove these '"' in django template

this is my code in homepage.html:

<script type="text/javascript">
 var jstree_jsondata={{json1}};
 alert(typeof jstree_jsondata)
</script>

and it show this in the source code :

var jstree_jsondata=
  [
   { &quot;data&quot; : &quot;kkkqq node&quot;, 
    &quot;attr&quot; : { &quot;id&quot; : &quot;ooo&quot; ,&quot;time&quot;:&quot;pp&quot;},
    metadata:&quot;i am the one&quot;,
    children&quot; : [ 
        { 

so how to remove all of the &quot; using django ,

thanks

like image 228
zjm1126 Avatar asked Dec 25 '10 06:12

zjm1126


People also ask

How do I get rid of unwanted Google Search results?

Log in to your account. Choose “Removal” from the “Index” menu. Select the “Temporary Removals” tab. Hit the “New Request” button (keep it on “Remove this URL only”) and enter the URL of the page you wish to remove entirely from search results and Google's cache.


1 Answers

Change the line:

var jstree_jsondata={{json1}}

to

var jstree_jsondata={{ json1|safe }}

This uses the safe filter to tell Django that the contents should be output literally without changing characters to html entities. The reason for the name 'safe' is that you are declaring that the data to be output is safe and will not be the origin of potential cross site scripting attacks or html that will break your layout.

like image 177
aaronasterling Avatar answered Oct 08 '22 11:10

aaronasterling