Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Render HTML in django template (not unicode but ASCII)

I understand that this is a little perverse, but I have a legacy database with some entries as formatted html. I'd like to just push this into my django templates as ASCII and let the browser display it.

Django kindly converts my fields to unicode, and so the browser displays the entire text <p> </p> etc. intact.

I was hoping that there might be a template flag {{ obj.text|ascii }} or something that might fix this for me - does anyone have any ideas? Thanks.

like image 499
danodonovan Avatar asked Apr 21 '11 22:04

danodonovan


People also ask

What does {{ this }} mean in Django?

{{ foo }} - this is a placeholder in the template, for the variable foo that is passed to the template from a view. {% %} - when text is surrounded by these delimiters, it means that there is some special function or code running, and the result of that will be placed here.

What does {% include %} do in Django?

The include tag allows you include a template inside the current template. This is useful when you have a block of content that are the same for many pages.

Is Django template Jinja?

The Django template language doesn't have an equivalent of Jinja2 tests.

What is render to string in Django?

render_to_string is a callable within the django. template. loader module of the Django project. get_template and select_template are a couple of other callables within the django. template.


1 Answers

From http://docs.djangoproject.com/en/dev/ref/templates/builtins/ what you want is:

{{ obj.text|safe }}
like image 132
Dan D. Avatar answered Sep 18 '22 16:09

Dan D.