Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在两个类别中显示视频列表1.&x27;当前用户';视频和2';其他用户';django中同一类的视频_Python_Django_Django Views_Django Templates - Fatal编程技术网

Python 如何在两个类别中显示视频列表1.&x27;当前用户';视频和2';其他用户';django中同一类的视频

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

下面的代码提供“其他用户”视频

下面的代码给出了“currentUser”视频

在模板中

{% 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 %}