98
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:
{{ value|linebreaks }}
If value is Joel\nis a slug
, the output will be <p>Joel<br />is a slug</p>.
6
Don’t use {% autoescape off %}
! Otherwise user controlled input may not get escaped, which is a security risk. As mentioned use linebreaks or linebreaksbr.
- [Django]-SocketException: OS Error: Connection refused, errno = 111 in flutter using django backend
- [Django]-Django aggregate or annotate
- [Django]-How to display the current year in a Django template?
0
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.
class Uadds(models.Model):
title = models.CharField(max_length = 50)
description = models.TextField(max_length = 1000)
title will not show line breaks, however, description will show them.
I haven’t tested this with a Rich Text Editor…
Hope this helped.
- [Django]-Whats the simplest and safest method to generate a API KEY and SECRET in Python
- [Django]-InterfaceError (0, '')
- [Django]-Running django tutorial tests fail – No module named polls.tests
- [Django]-How do I remove Label text in Django generated form?
- [Django]-How do I create multiple model instances with Django Rest Framework?
- [Django]-Django South – table already exists