Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have this string

{{contact.info}}

The value is:

name teste\[email protected]\n(11) 11111-1111\n(0) 12312-3123\n(12) 12312-3123\n

In html I want to see it:

name teste
[email protected]<br>
(11) 11111-1111
(10) 12312-3123
(12) 12312-3123

Have any way?

like image 549
brunozrk Avatar asked Dec 20 '22 02:12

brunozrk


1 Answers

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 %}
like image 151
Joseph Victor Zammit Avatar answered Jan 12 '23 00:01

Joseph Victor Zammit