bru*_*zrk 4 python django django-templates popover twitter-bootstrap
我有这个字符串
{{contact.info}}
Run Code Online (Sandbox Code Playgroud)
该值是:
name teste\nteste@teste.com.br\n(11) 11111-1111\n(0) 12312-3123\n(12) 12312-3123\n
Run Code Online (Sandbox Code Playgroud)
在 html 我想看到它:
name teste
teste@teste.com.br<br>
(11) 11111-1111
(10) 12312-3123
(12) 12312-3123
Run Code Online (Sandbox Code Playgroud)
有什么办法吗?
使用autoescape模板标记转义 HTML 换行符 ( <br />) 字符。
此外,由于您没有 html 换行符,您必须使用linebreaksbrDjango 模板过滤器将文本文件换行符转换为 HTML 换行符,如本答案中所建议。
您的代码应如下所示:
{% autoescape on %}
{{ contact.info | linebreaksbr }}
{% endautoescape %}
Run Code Online (Sandbox Code Playgroud)
你想要的linebreaks过滤器:
{{contact.info | linebreaks}}
Run Code Online (Sandbox Code Playgroud)
contact.info话虽这么说,如果是一个列表会更好- 那么你可以这样做:
{% for info in contact.info %}
{{ info }}<br />
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8187 次 |
| 最近记录: |