Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django - Store unescaped html in model

I am trying to store raw, unescaped HTML inside one of my Django models for display on my home page. However, when I store it in a TextField it gets escaped, and ends up just being displayed as raw text. How can I store raw HTML in a Django model?

** EDIT **

It seems as if its not getting escaped in the model layer, but in the Template layer. Is there a special tag I should use? I checked the value in the shell and it's just fine, but for some reason when i did {{ block.html } (html is the attribute of the block object that stores the actual HTML) in the template, it comes out like this:

<p>This is a <strong>very</strong> <em>important</em> <span style="text-decoration: underline;">block</span></p>
<p style="padding-left: 30px;">it has very significant content!</p>
like image 776
The.Anti.9 Avatar asked Jan 26 '10 06:01

The.Anti.9


1 Answers

You can use the safe filter to present unescaped text, or escape filter to present escaped text. You can also use autoescape tag to set a block. ({% autoescape on %} or {% autoescape off %})

like image 64
Khelben Avatar answered Oct 18 '22 21:10

Khelben