Reputation: 625
I am trying to render a message in a template using django. I used this code:
message = "hello <br /> how are you? "
t = loader.get_template(template_html)
context = {"message":message}
return t.render(context)
The problem is that:
I get hello <br /> how are you?
in the template instead of a new line, how can I fix this?
Upvotes: 1
Views: 2686
Reputation: 73450
You can either apply the safe
filter in the template or mark message
as safe in the view:
# template
{{ message|safe }}
or
# view
from django.utils.safestring import mark_safe
context = {"message": mark_safe(message)}
This will then render your message as html.
Upvotes: 5