[英]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.