[英]How to print list data in next line in Django
在这里,我通过 for 循环将一些数据放入列表中,这应该打印在下一行
让我们将我的 views.py 视为
def items_log(request, pk):
logg = []
client = request.user.client
items_log = JobItemsLogs.objects.filter(client=client,item_id=pk).order_by('-id')[:5]
for x in items_log:
log_text = 'Type of entry: {0} - date: {1}; Created by: {2}'.format(
x.type_of_entry,x.created_at.date(),x.created_by)
logg.append(log_text)
...
...
...
现在让我们通过 index.html 考虑为
<div class="span4">
<div class="well">
<ul class="nav nav-list">
<li class="nav-header" >Log entries</li>
{% for i in logg %}
{{i}}
{% endfor %}
</ul>
</div>
</div>
这里是如何显示的
我想如何显示是
Type of entry: Plumbing - date: 2021-11-02; Created by: A Krishna*
Type of entry: Plumbing - date: 2021-11-02; Created by: A Krishna*
Type of entry: None - date: 2021-07-28; Created by: A Krishna*
Type of entry: None - date: 2021-07-28; Created by: A Krishna*
Type of entry: None - date: 2021-07-28; Created by: A Krishna*
这些列表数据中的每一个都应该在新行中看到
只需将{{i}}
放在p
标签中! :D
<p>{{i}}</p>
或者您可以添加<br>
:
{{i}}<br>
在行后添加一个换行符 -
log_text = 'Type of entry: {0} - date: {1}; Created by: {2}<br>'.format(
x.type_of_entry,x.created_at.date(),x.created_by)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.