Search code examples
djangotemplatesdjango-templateshtml-encode

Is is possible to html encode output in AppEngine templates?


So, I'm passing an object with a "content" property that contains html.

<div>{{ myobject.content }}</div>

I want to be able to output the content so that the characters are rendered as the html characters.

The contents of "conent" might be: <p>Hello</p>

I want this to be sent to the browser as: &lt;p&gt;Hello&lt;/p&gt;

Is there something I can put in my template to do this automatically?


Solution

  • Yes, {{ myobject.content | escape }} should help (assuming you mean Django templates -- there's no specific "App Engine" templating system, GAE apps often use the Django templating system); you may need to repeat the | escape part if you want two levels of escaping (as appears to be the case in some but not all of the example you supply).