Search code examples
pythondjangotwitter-bootstrapdjango-templatespopover

Is there any way to allow \n in a django template? (bootstrap-popover)


I have this string

{{contact.info}}

The value is:

name teste\nteste@teste.com.br\n(11) 11111-1111\n(0) 12312-3123\n(12) 12312-3123\n

In html I want to see it:

name teste
teste@teste.com.br<br>
(11) 11111-1111
(10) 12312-3123
(12) 12312-3123

Have any way?


Solution

  • Use the autoescape template tag to escape HTML linebreak (<br />) characters.

    In addition, since you do not have html linebreak characters, you have to convert your text file newlines to HTML linebreaks, using the linebreaksbr Django template filter, as suggested in this answer.

    Your code should look like:

    {% autoescape on %}
        {{ contact.info | linebreaksbr }}
    {% endautoescape %}