Rendering a template variable as HTML
If you want to do something more complicated with your text you could create your own filter and do some magic before returning the html. With a templatag file looking like this:
from django import template
from django.utils.safestring import mark_safe
register = template.Library()
@register.filter
def do_something(title, content):
something = '<h1>%s</h1><p>%s</p>' % (title, content)
return mark_safe(something)
Then you could add this in your template file
<body>
...
{{ title|do_something:content }}
...
</body>
And this would give you a nice outcome.
Use the autoescape
to turn HTML escaping off:
{% autoescape off %}{{ message }}{% endautoescape %}
If you don't want the HTML to be escaped, look at the safe
filter and the autoescape
tag:
safe
:
{{ myhtml |safe }}
autoescape
:
{% autoescape off %}
{{ myhtml }}
{% endautoescape %}