Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: show raw html (from database) as html, not rendered

I have created a rich text area using tinymce. I have now saved this to my database and want to display it. It gets saved in the database as html with tags, etc. To display it I have tried:

In views:

content = get_content_from_db() render_to_response("template.html", {"content":content}) 

In template:

{{content}} 

This shows the content with the tags like so:

<strong>My text</strong> 

instead of just displaying the text as bold.

I have also tried using the verbatim tag, but this (doh!) displays as:

{{content}} 

How should I do this? Do I need to save it differently? I save it the way I save any other TextArea except the field is a blob.

like image 500
user984003 Avatar asked Nov 05 '12 08:11

user984003


People also ask

What non HTML output can Django generate?

Django has convenient built-in tools that you can use to produce some common non-HTML content: RSS/Atom syndication feeds. Sitemaps (an XML format originally developed by Google that gives hints to search engines)

What does {% include %} do in Django?

From the documentation: {% extends variable %} uses the value of variable. If the variable evaluates to a string, Django will use that string as the name of the parent template. If the variable evaluates to a Template object, Django will use that object as the parent template.


1 Answers

Use safe filter

{{ content|safe }} 
like image 121
DrTyrsa Avatar answered Sep 21 '22 05:09

DrTyrsa