开发者

how to remove these '"' in django template

开发者 https://www.devze.com 2023-02-01 17:38 出处:网络
this is my code in homepage.html: <script type=\"text/javascript\"> var jstree_jsondata={{json1}};

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 sourc开发者_高级运维e 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消