开发者

django unescape script tag

#base.html
{% autoescape off %} 
/开发者_如何学Python/<![CDATA[
{% block inline_script %}{% endblock %}
//]]>
{% endautoescape %}
#some template
{% block inline_script %}
    {% autoescape off %} 
    <script type="text/javascript" charset="utf-8">
        alert('a');
    </script>
    {% endautoescape %}
{% endblock %}

result:

// alert('a'); //]]&gt ;

Why this happens? Hot to fix it?


I suspect the problem starts here:

//<![CDATA[

The template generates HTML, and // is not a valid HTML comment. Try removing the slashes to see what happens.

Also, consider viewing the HTML source that is produced by this template. You can validate it to find other errors.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜