I have this Django view that does render_to_response(rss.xml, {"list":list}) with this list:
<a href="link.html">description</a>
<a href="link2.html">description2</a>
<a href="link3.html">description3</a>
the rss.xml template is the following:
<?xml version="1.0" encoding="UTF-8"?><rss version="0.92">
{% for item in list%}
{{item}}
{% endfor %}
This works, however the <'s and "'s get replaced by their special html charactervalues like:
<?xml version="1.0" encoding="UTF-8"?><rss version="0.92">
<a href="link.html">Description</a>
<a href="link2.html">Description2</a>
<a href="link3.html">Description3</a>
how can I just output the raw strings such that the document becomes:
<?xml version="1.0" encoding="UTF-8"?><rss version="0.92">
<a href="link.html">description</a>
<a href="link2.html">description2</a>
<a href="link3.html">description3</a>
You should surround the for block with autoescape tags like so:
<?xml version="1.0" encoding="UTF-8"?><rss version="0.92">
{% autoescape off %}
{% for item in list%}
{{item}}
{% endfor %}
{% endautoescape %}
django won't escape the characters between the autoescape tags
see here: https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs#autoescape
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With