How to render links in my CharField/TextField DB column as HTML in Django
A snippet of my template -
{% block content %}
{{ messag开发者_开发百科e.subject }}
{{ message.content }}
{% endblock %}
My message.content = " Check this out - /<a href="http://RigWave.In"> RigWave </a> "
If you want to render as HTML (as a link) like this -
" Check this out - RigWave "
After looking at your unedited post, I'm wondering if you replaced the link tags with [ to prevent SO from rendering it as a link (though `` takes care of it).
If you actually have properly formatted links in the CharField, you need to mark the string as safe to prevent auto HTML escaping.
{{ message.content|safe }}
or
{% autoescape off %}
{{ body }}
{% endautoescape %}
http://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters first sample is perfect, you could use custom filter or use .replace
精彩评论