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'); //]]> ;
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.
精彩评论