0

I have a database table for my blog entries where I save certain content as html code. Then I load this content and expect it to excute the html code, but it does not do it. All the html code symbols seem broken.

My DB column:

enter image description here

Loading column content in template (red square shows where I want to load the column content:

enter image description here

HTML code after the column content has been loaded:

enter image description here

enter image description here

Is there a way to load this properly so the html will be executed, because in the DB it looks ok.

Thanks!

Roman
  • 3,563
  • 5
  • 48
  • 104

1 Answers1

1

Your HTML content is being escaped by Django as a default behavior. To mark this content as safe for rendering, you can use the safe template filter:

Marks a string as not requiring further HTML escaping prior to output. When autoescaping is off, this filter has no effect.

In your example, this should work:

{{ blog.bloginhalt|safe }}

Alternatively, if you have many tags that will need to be marked as safe, you can set autoescape to on for a whole block:

{% autoescape off %}
    {{ tag1 }}
    {{ tag2 }}
    {{ tag3 }} <!-- all these tags are not escaped -->
{% endautoescape %}
brianpck
  • 8,084
  • 1
  • 22
  • 33