supermario
supermario

Reputation: 2755

How to preseve newline in django posts without using a WYSIWYG editor?

I am using django's forms class along with it's cleaned_data method to get user posts/comments. The problem is that the newlines are not preserved in the cleaned_data field so

The firs line of comment.
And the second lines.

Ends up being

The firs line of comment. And the second lines.

Which is not good.

How to avoid this without using a WYSIWYG editor?

Upvotes: 0

Views: 127

Answers (1)

Brandon Taylor
Brandon Taylor

Reputation: 34573

If you're referring to the output of the value held in the field, you just need to use the linebreaks or linebreaksbr filter: https://docs.djangoproject.com/en/1.7/ref/templates/builtins/#linebreaks

{{ instance.field|linebreaks }}

or

{{ instance.field|linebreaksbr }}

to get the correct formatting without having to use a wysiwyg editor.

Upvotes: 2

Related Questions