Python 如何在两个类别中显示视频列表1.&x27;当前用户';视频和2';其他用户';django中同一类的视频
下面的代码提供“其他用户”视频 下面的代码给出了“currentUser”视频 在模板中Python 如何在两个类别中显示视频列表1.&x27;当前用户';视频和2';其他用户';django中同一类的视频,python,django,django-views,django-templates,Python,Django,Django Views,Django Templates,下面的代码提供“其他用户”视频 下面的代码给出了“currentUser”视频 在模板中 {% for vid in object_list %} {% if forloop.counter < 5 %} {{ vid.video }} {% endif %} {% endfor %} {%用于对象列表%中的vid} {%if-forloop.counter
{% for vid in object_list %}
{% if forloop.counter < 5 %}
{{ vid.video }}
{% endif %}
{% endfor %}
{%用于对象列表%中的vid}
{%if-forloop.counter<5%}
{{vid.video}
{%endif%}
{%endfor%}
我的要求是显示两个类别的视频列表
1.当前用户视频列表
和
2.其他用户视频列表
在应该显示在同一html页面上的同一类“Test”中,您需要定义方法
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["other_video_list"] = VideoUpload.objects.exclude(user=self.request.user)
return context
然后在模板中可以使用
{% for other_vid in other_video_list %}
...
{% endfor %}
覆盖获取上下文数据(self,**kwargs)完美,谢谢@Maslov AndreyThank you@Blackdoor
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["other_video_list"] = VideoUpload.objects.exclude(user=self.request.user)
return context
{% for other_vid in other_video_list %}
...
{% endfor %}