【发布时间】:2021-04-22 15:40:14
【问题描述】:
我有模型“视频”并且我有这个模型的列表视图,然后在另一个应用程序中我试图创建一个专用用户可以查看的视图“UserVideosListView”。当我在为此视图制作任何模板之前在浏览器中打开页面时,我可以看到当前用户的视频(不是所有视频)。
# inside 'users' app
class UserVideosListView(ListView):
model = Video
template_name = "users/user_videos.html"
context_object_name = 'videos'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['videos'] = Video.objects.filter(author=self.request.user)
return context
# inside 'videos' app
class VideoListView(ListView):
model = Video
paginate_by = 25
template_name = 'videos/video_list.html'
context_object_name = 'videos'
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['videos'] = Video.published_videos.all()
return context
附:我确定我输入的 URL 是最新的,并且“用户”目录中没有模板
【问题讨论】:
标签: python python-3.x django django-3.1