【发布时间】:2021-12-17 21:28:28
【问题描述】:
这里我通过 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*
这些列表数据中的每一个都应该在新行中看到
【问题讨论】:
-
- 用于列表项,所以它应该是
{% for i in logg %}<li> {{i}}</li> {% endfor %} - 用于列表项,所以它应该是
-
<div> {{i}} </div>或者你可以像{{i}} <br>这样在末尾添加换行符
标签: python django django-models django-views django-templates