Rendering a text field and charfield chomps out of extra spaces (Django / Python)

I noticed that my template provides my .CharField and model.TextField model without extra spaces.

For example, if I enter data such as ...

This     is a           test


to see what  happens.

The displayed field of the object will appear as ...

This is a test to see what happens.

Is this an intentional Django function, or am I missing a filter or parameter somewhere?

I myself checked the field with some debugging code (print object.field), and it contains extra spaces, so the problem is with the rendering side.

How can I let the user enter paragraphs of data in TextFields? How to save spaces that the user could enter?

+5
source share
1 answer

StackOverflow, , :

This     is a           test


to see what  happens.

:

This     is a           test\n\n\nto see what  happens.

html:

  • , <pre></pre>

  • , , <pre></pre>.

, html: &nbsp;.

HTML, linebreaksbr . , {{ foo }}: test\nbar, {{ foo|linebreaksbr }} : test<br />bar

  • templatetags __init__.py.

  • , , someapp/templatetags/replace_tag.py

  • {% load replace_tag %}

  • replace linebreaksbr : {{ foo|linebreaksbr|replace:" ","&nbsp;" }}

, HTML-.

+12

All Articles