Python Django呈现指定目录中不存在的模板

Python Django呈现指定目录中不存在的模板,python,python-3.x,django,django-3.1,Python,Python 3.x,Django,Django 3.1,我有一个模型“视频”,我有一个这个模型的列表视图,然后在另一个应用程序中,我试图创建一个视图“UserVideosListView”,该视图可供专用用户查看。在为该视图制作任何模板之前,当我在浏览器中打开页面时,我可以看到当前用户的视频(不是所有视频) 另外,我确信我输入的URL是最新的,并且“用户”目录中没有模板,Django呈现视频/video_list.html,因为ListView基于multipleobjecttemplaterresponsemixin和BaseListView:

我有一个模型“视频”,我有一个这个模型的列表视图,然后在另一个应用程序中,我试图创建一个视图“UserVideosListView”,该视图可供专用用户查看。在为该视图制作任何模板之前,当我在浏览器中打开页面时,我可以看到当前用户的视频(不是所有视频)



另外,我确信我输入的URL是最新的,并且“用户”目录中没有模板,Django呈现视频/video_list.html,因为
ListView
基于
multipleobjecttemplaterresponsemixin
BaseListView

在()中,模板名称也基于模型生成

说:

模板\名称\后缀

要附加到自动生成的候选模板名称的后缀。默认后缀是\u list

返回候选模板名称的列表。返回以下列表:

  • 视图上模板名称的值(如果提供)
  • /.html

我建议您重写
get\u queryset()
方法,而不是
get\u context\u data()

类用户视频列表视图(列表视图):
型号=视频
上下文\对象\名称='视频'
...
def get_queryset(自我):
return super().get_queryset().filter(author=self.request.user))

我们不是用“模板名称”来忽略这个吗?@KuroshGhanizadeh,是的,没错,但模板应该存在(找到)。@KuroshGhanizadeh,你想做什么?为用户创建一个页面,以便在仪表板中查看他们的视频谢谢。你是对的。那是因为它在那个目录里没有找到任何东西
# 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
class ListView(MultipleObjectTemplateResponseMixin, BaseListView):
    """
    Render some list of objects, set by `self.model` or `self.queryset`.
    `self.queryset` can actually be any iterable of items, not just a queryset.
    """
# If the list is a queryset, we'll invent a template name based on the
# app and model name. This name gets put at the end of the template
# name list so that user-supplied names override the automatically-
# generated ones.
if hasattr(self.object_list, 'model'):
    opts = self.object_list.model._meta
    names.append("%s/%s%s.html" % (opts.app_label, opts.model_name, self.template_name_suffix))
class UserVideosListView(ListView):
    model = Video
    context_object_name = 'videos'
    ...

    def get_queryset(self):
        return super().get_queryset().filter(author=self.request.user))