Formatting html Django-cms - django

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 }}.

Related

Is it possible to display the HTML provided by the admin panel app on-site?

I've built a site where I can create new posts (essays) by the admin panel. The output is visible to users. But when I place some HTML as content in the form it doesn't render itself on the page.
example:
Output on the page (with marked unrendered HTML):
I would like to know how to fix it and also, how to name the topic I want to know ( I couldn't find anything related to my problem, probably because I don't know how to express it).
Additionally, I just start to wonder if there is one more problem nested inside. How to link CSS from the static folder having this HTML mentioned above?
Django offer the autoescape template in the builtins tags
{% autoescape off %}
{{ myhtml }}
{% endautoescape %}
But your logic seems wrong, you don't need to create a new page with the doctype, just create a base template and use the block content tag to insert your article.
In your base template replace the description and title of your page by variables that will be populated by the article data.
You need to learn the basic of Django https://docs.djangoproject.com/en/4.1/ trust me you won't regret it !

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.

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

Problem with displaying content made with WYSIWYG in django admin

In one of my projects there was need to implement WYSIWYG-editor into django admin. I've installed http://code.google.com/p/django-tinymce/. Everything works well, but there is a problem with rendering the content made with WYSIWYG-editor. As a result, on html page returns special chars instead of normal html-tags and I see "plain" html tags with no html-layout.
Maybe the problem is in the templates? I simply output variable like {{ content }}
try {{ content|safe }}
Marks a string as not requiring
further HTML escaping prior to output.
via safe

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