How do I allow line breaking in textarea input in django to later show this input on page?
相关问题
- Views base64 encoded blob in HTML with PHP
- Django __str__ returned non-string (type NoneType)
- Is there a way to play audio on a mobile browser w
- HTML form is not sending $_POST values
- implementing html5 drag and drop photos with knock
I had a text area for user minimal custom input in the template and I wanted to keep whatever formatted text the user inserted to stay the same. The solution, I simply changed the Model variable to a TextField type. It even shows the user formatted text in the admin. :)
ex.
title will not show line breaks, however, description will show them. I haven’t tested this with a Rich Text Editor... Hope this helped.
linebreaks
Replaces line breaks in plain text with appropriate HTML; a single newline becomes an HTML line break (
<br />
) and a new line followed by a blank line becomes a paragraph break (</p>
).For example:
If value is
Joel\nis a slug
, the output will be<p>Joel<br />is a slug</p>.
Use
{% autoescape off %} {{ your_variable }} {% endautoescape %}
.Don't use
{% autoescape off %}
! Otherwise user controlled input may not get escaped, which is a security risk. As mentioned use linebreaks or linebreaksbr.