Is it possible to html encoding the output in AppEngine templates?
So I am passing in an object with a content property containing the html.
<div>{{ myobject.content }}</div>
I want to be able to output content so that characters are displayed as HTML characters.
The "conent" content can be: <p> Hello </p>
I want this to be sent to the browser as: & ampl; p & ampgt; Hello & amplt; / p & gt;
Is there something I can add to my template to do this automatically?
a source to share
Yes, it {{ myobject.content | escape }}
should help (assuming you mean Django templates - there is no specific App Engine templating system, GAE apps often use the Django templating system); you may need to repeat the part | escape
if you want two levels of escaping (as is the case in some, but not all of the examples you supply).
a source to share
This is the Django function django.utils.html.escape:
def escape(html):
"""Returns the given HTML with ampersands, quotes and carets encoded."""
return mark_safe(force_unicode(html).replace('&', '&').replace('<', '&l
t;').replace('>', '>').replace('"', '"').replace("'", '''))
Also see here .
a source to share