[Python] How do I avoid Django's `|linebreaksbr` and Bootstrap style conflict?

Discussão em 'Python' iniciado por Stack, Maio 17, 2025.

  1. Stack

    Stack Membro Participativo

    I'm trying to store newline character inside model's CharField but it's not rendering correctly. <br/> and <br> both display as plain text, while |linebreaksbr is destroing bootstrap's styles in that text.

    3 of my attempts to make it work:

    <p>{{ greetings.title_2 }}</p>
    <p><pre>{{ greetings.title_2 }}</pre></p>
    <p>{{ greetings.title_2 | linebreaksbr }}</p>


    And the result looks like this: [​IMG]

    I want both bootstrap's style (like in first line) and new line stored inside variable. There is a way to do that by deviding one model field in two and adding <br/> tag into html file, but I wonder if there is better and simpler way for that. Any ideas?

    Continue reading...

Compartilhe esta Página