Django: Passing HTML string to template

本小妞迷上赌 提交于 2019-12-05 00:49:45

Problem solved. Wasn't as dramatic as I thought. It so happens that django was converting html tokens such as '<' and '>' to '&lt' and '&gt'

This resulted in a correct output on the page, but inability to create the corresponding DOM objects.

the fix:

 {% autoescape off %}
    {% for book, book_desc in bd.items %}
       books_description["{{ book }}"] = "{{ book_desc|escapenewline }}"
    {% endfor %}
 {% endautoescape %}

Took me a while. If anyone comes across a similar issue here's some intel on autoescaping

autoescape filter

in case someone lands here for recent django versions use {{ your_context_entry|safe }}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!