python - 不同的行不会出现在 Django 的上下文中
问题描述
如果我有类似的代码
hello_worlds = 'hello Earth \n hello Mars'
context = {
'hellos':hello_worlds
}
return render(request, 'home.html', context)
home.html 是
{{hellos}}
它显示为
hello Earth hello Mars
不是
hello Earth
hello Mars
我正在使用 Django 2.1.5 和 python 3.8 有没有办法让它像第二个一样显示?
解决方案
我想前两个家伙已经回答了。
您不需要在视图中换行,因为您可以使用“换行符”模板过滤器在模板中执行此操作,就像他们说的那样:
{{hellos|换行符}}
或者,
{{hellos|换行符}}
推荐阅读
- unity3d - 如何使 Vector3 字段的行为类似于 CustomEditor 中的 Transform 字段
- python - 我得到错误的python输出格式。我究竟做错了什么?
- swift - iOS 11:完全替换设备旋转的子视图
- python - 如何制作第二和第三金字塔
- d3.js - 为什么这个 D3 exit() 代码没有按预期工作?
- android - Firebase Android,设置x = x的值?
- .net - 如何正确设置 Connection 标头?
- java - 无法生成签名的 APK
- node.js - Mongoose:根据 id 填充数组
- python-3.x - 从文件路径导入模块非常慢有什么解决方案吗?