[英]Django Queryset : How to print second value in queryset?
I'd like to print only second value in queryset.我只想在查询集中打印第二个值。
views.py:视图.py:
def all_chatroom(request, user_obj):
current_user = user_obj
conversations = models.Conversation.objects.filter(participants=user_obj)
return render(
request,
"conversations/all.html",
{"conversations": conversations, "current_user": current_user},
)
templates>all.html:模板>所有.html:
{% extends "partials/base.html" %}
{% block page_name %} 메세지 목록 {% endblock page_name %}
{% block content %}
<div class="container">
{% for conversation in conversations %}
<div class="border">
{{conversation.participants.all}}
</div>
{% endfor %}
</div>
{% endblock content %}
and the printing value for the template is模板的打印值为
<QuerySet [<User: master>, <User: test1>]>
<QuerySet [<User: master>, <User: test2>]>
for this example, I want to print test1 and test2 .对于这个例子,我想打印test1和test2 。 how can I print only second value in queryset?
如何在查询集中只打印第二个值?
The second item would be queryset[1]
第二项是
queryset[1]
In your template can use {{ queryset.1}}
在您的模板中可以使用
{{ queryset.1}}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.