I have a text field in my MySQL table. I want to format all new lines with the <br> or some sort of formatting for the template. Is there anything built into the framework for this? I tried to read into the following page:
https://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs
But seems like that page won’t work for this? Is there another documentation I can refer to? Thanks!
It sounds like you need the
linebreaksbrtemplate filter.Normally, you would use it in the template:
However, it’s possible to import it and use it in your view as well:
The advantage of using
linebreaksbrinstead of writing your own snippet, is that the linebreaksbr takes care of autoescaping for you.