python - 防止 Django 模板中的换行符分割名称列表

标签 python html django

我有一个人员姓名列表,我将其传递给 django 模板,然后将其显示为 HTML 表格单元格中以逗号分隔的字符串:

{{ list_of_names|join:", " }}

效果很好,但有时它会在换行符处分隔名字和姓氏。如何防止这种情况并确保每个新行都以名字开头?

最佳答案

类似这样的事情:

{% for name in list_of_names %}
   <div style="float: left">{{ name }}{%
     if forloop.counter0 %}, {% endif 
   %}</div>
{% endfor %}

关于python - 防止 Django 模板中的换行符分割名称列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25066700/

相关文章:

python - python 中区分字符串

python - 在 Django 中实例化 View 类时出错

python - Django 更新表

python - 自动化测试中如何初始化 session 数据? (python 2.7、webpy、nosetests)

python - 如何复制在 Python 函数调用中不会更改的列表

html - 在 HTML 中漂亮地打印 JSON 字符串

html - Doctype 破坏了 flexbox 布局

python - 将 Django 管理显示时间设置为本地时间?

Python创建目录报错Cannot create a file when that file already exists

html - 在 HTML 中创建标题