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

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.

Use safe filter
{{ content|safe }}

Related

How do I remove <p> tag from django richtextfield?

I am getting p tag displayed after I post an image or question with ckeditor editor in Django. .How can I remove the tag and get the image or text be displayed correctly.
You need to explicitly state that the content in template should be considered safe. You can use safe filter (Django docs) to do that so for variable text_content in your template you should do {{ text_content | safe }}.

How to render html text from database inside a django template using template tags

I save a text into my database using django form, textarea widget and bootstrap wysiwyg, but when I try to render it into my template using just the variable name
{{ text }},
I get rendered just the text with html tags like this:
what I want to do is show the formatted text in html.
If you have the formatted HTML in your DB-field, and you absolutely sure is it safe, then try safe filter
{{ tablename.fieldname|safe }}
or
{{var|safe}}
See the doc.

Formatting html Django-cms

I create a app, where I can put html code like this
<h2>where we are?</h2>
<h4>Main Offices</h4>
My problem is when I show in my view I see the text with the html tags,
I try this {{ item|striptags }} but this remove the html tag from the page, even when I inspect the element it's look like string
"where we are? Main Offices"
What is the way in django-cms to don't see the html tag in the view, but when I inspect the element the tags is there!
Django automatically escapes the output of every variable tag, to protect you from Cross-site scripting. You can disable auto-escaping by using the safe template filter: {{ item|safe }}.

WYSIWYG editor pastes html tags in output textfield

I use this redactor for admin site django-wysiwyg-redactor
But when I enter some text, it pastes it with html tags. When discovering my source code, I noticed that html code that is responsible for my input data, is placed in quotes.
I think you have to use "safe", the built-in template filter to render the html properly in your template. Example:
{{ myTextField|safe }}
Safe in django docs

Django textarea widget <p>

In django admin I am using the textarea widget.
When I save data, it is saved inside a <p></p> tag.
I dont want this - any solutions, I just want to get the data out without being wrapped in a <p>.
Any suggestions?
I don't know how to save it without html coding, but maybe it is enough to you to display without that . Just put a |safe in the template after the variable name, example:
{{ variable|safe }}
http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs