Python 是否有任何方法允许在django模板中使用\n?(引导弹出框)

Python 是否有任何方法允许在django模板中使用\n?(引导弹出框),python,django,twitter-bootstrap,django-templates,popover,Python,Django,Twitter Bootstrap,Django Templates,Popover,我有这根绳子 {{contact.info}} 该值为: name teste\nteste@teste.com.br\n(11) 11111-1111\n(0) 12312-3123\n(12) 12312-3123\n 在html中,我想看到它: name teste teste@teste.com.br<br> (11) 11111-1111 (10) 12312-3123 (12) 12312-3123 name teste teste@teste.com.br (11

我有这根绳子

{{contact.info}}
该值为:

name teste\nteste@teste.com.br\n(11) 11111-1111\n(0) 12312-3123\n(12) 12312-3123\n
在html中,我想看到它:

name teste
teste@teste.com.br<br>
(11) 11111-1111
(10) 12312-3123
(12) 12312-3123
name teste
teste@teste.com.br
(11) 11111-1111 (10) 12312-3123 (12) 12312-3123
有什么办法吗?

使用转义HTML换行符(

)字符

此外,由于没有html换行符,因此必须使用中建议的将文本文件换行符转换为html换行符

您的代码应该如下所示:

{% autoescape on %}
    {{ contact.info | linebreaksbr }}
{% endautoescape %}
您需要过滤器:

也就是说,如果
contact.info
是一个列表会更好,那么您可以:

{% for info in contact.info %}
{{ info }}<br />
{% endfor %}
{%用于contact.info%中的信息]
{{info}}
{%endfor%}
问题不在于模板,而在于HTML中的换行符没有任何作用……有什么办法吗?比你快4秒,但你提供了链接,所以有+1.)@Wooble-咯咯笑着,你删除了你的帖子,所以我不能+1你打败我。不允许使用html标记,正在打印
@user2092913-你可能需要在
换行符之后添加一个过滤器(我认为这是一个bug,对于你正在使用的Django版本)。我在另一个回答中是这样说的,我使用的是bootstrap中的popover。当它直接在html中工作时,但当我把它放在占位符中时,它不允许使用html标记…@user2092913现在它应该;)不允许html标记,正在打印
哦,当我尝试直接用html打印时,它可以工作,但是我使用bootstrap中的popover,占位符可能会做一些事情:数据内容=“{{contact.info | linebreaksbr}}”应该可以工作,因为您正在使用
autoesacpe on
转义html,如果您不渲染它怎么办?我想将
\n
字符放入输入字段的
值中。有没有办法用django模板语言保留
\n
字符?
{% for info in contact.info %}
{{ info }}<br />
{% endfor %}