Django: Passing HTML string to template

后端 未结 2 976
清酒与你
清酒与你 2021-02-07 05:44

I\'m having an issue while trying to display a html chunk of code created on a django view. Here\'s what\'s happening.

On my view, I\'m trying to pass to the template a

2条回答
  •  野性不改
    2021-02-07 06:06

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

    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

提交回复
热议问题