how to include html in your text area

119 views
Skip to first unread message

joy

unread,
Dec 6, 2012, 1:07:32 PM12/6/12
to django...@googlegroups.com
May i use html inside a text area? (i need some link in my text but the TextField of my object Text gives me back the html without formatting it)

Is there any workaround?

Joy

Jonathan Baker

unread,
Dec 6, 2012, 1:10:28 PM12/6/12
to django...@googlegroups.com
The html is saved to the database, but is stripped out when the variable is rendered to the template to help prevent XSS attack. You can read more about it (including how to selectively disable the feature) here: https://docs.djangoproject.com/en/dev/topics/templates/#automatic-html-escaping


Joy

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/IDV8W_JN-9YJ.
To post to this group, send email to django...@googlegroups.com.
To unsubscribe from this group, send email to django-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

Mario Gudelj

unread,
Dec 6, 2012, 5:13:25 PM12/6/12
to django...@googlegroups.com
HTML is not really stripped. It's just encoded. If you want to render it on the frontend you can use https://docs.djangoproject.com/en/dev/ref/templates/builtins/#std:templatefilter-escape or safe filter e.g. {{ your_var|safe }}

Cheers,

-mario

Pedro J. Aramburu

unread,
Dec 6, 2012, 9:26:06 PM12/6/12
to django...@googlegroups.com
Joy, look into the database if it is being saved without escaping. If that's the case you need to render it without escaping marking it as safe with the safe filter. For example:
This will not be escaped: {{ data|safe }}
or you can use a template block like this:

{% autoescape off %}
    Hello {{ name }}
{% endautoescape %}

If you wan't some text field where you can format take a look at:


or

Reply all
Reply to author
Forward
0 new messages