07/13/2021 12:08 | Category: django

Tags: pythondjangofrontend

django linebreaksbr

During some client work my friend and I ran into an issue where we didn't want a full "rich text" style on a Django template (the client uses WagTail), but instead just show linebreak/carriage returns in a <p> element.

This can be accomplished in two ways:

  1. Showing a |linebreaks which changes the displays to blocks
  2. Showing a |linbreaksbr which changes the carriage returns to <br> elements

Link to the StackOverflow we found

Example intended result:

This text would have a

linebreak

Actual display:

This text would have a linebreak

Changing the display:

<div>
    <p>
        {{ some_text|linebreaksbr}}
    </p>
</div>