首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未找到'list_videos‘在/ NoReverseMatch /list/ Reverse处的视频。“list_videos”不是有效的视图函数或模式名称

未找到'list_videos‘在/ NoReverseMatch /list/ Reverse处的视频。“list_videos”不是有效的视图函数或模式名称
EN

Stack Overflow用户
提问于 2020-09-21 08:40:08
回答 1查看 66关注 0票数 0

嗯,我正在尝试创建一个与YouTube非常相似的播放列表。但是播放列表只能由超级用户从管理面板创建,其他用户只能看到该播放列表和播放列表中的视频。当我认为我做完了,然后突然发生了这个错误。我不知道我在哪里弄错了。请帮我解决这个问题。

视频/models.py

代码语言:javascript
复制
class VideosList(models.Model):

    list_title = models.CharField(max_length=255)
    list_cover = models.ImageField(upload_to='list cover', height_field=None, width_field=None, max_length=None,blank =True)
    create_date = models.DateField(default = timezone.now)

    def __str__(self):
        return self.list_title

class VideosModel(models.Model):

    
    videos_lists = models.ForeignKey(VideosList,on_delete=models.CASCADE) 
    video_title = models.CharField(max_length=250)
    video_url = models.URLField(max_length=1200)
    video_discription = models.TextField()
    create_date = models.DateField(default = timezone.now)


    def __str__(self):
        return self.video_title 

videos/views.py

代码语言:javascript
复制
class VideosListView(ListView):
    model = VideosList
    context_object_name = 'videos_lists'  
    template_name = "videos/videos_lists.html"

    def get_queryset(self):
        return VideosList.objects.filter(create_date__lte=timezone.now()).order_by('-create_date')





class VideosModelListView(ListView):
    model = VideosModel
    template_name = "videos/list_videos.html"
    context_object_name = 'videos_list'  

    def get_queryset(self,*args, **kwargs):
        videoslist = get_object_or_404(VideosList, list_title=self.kwargs.get('list_title'))
        return VideosModel.objects.filter(videos_lists=videoslist).order_by('-create_date')

视频/urls.py

代码语言:javascript
复制
app_name = 'videos'

urlpatterns = [
    path('list/',views.VideosListView.as_view(),name ='videos_playlist'),
    path('list/<str:list_title>/',views.VideosModelListView.as_view(),name ='list_videos'),
]

videos/videos_list.html

代码语言:javascript
复制
{% extends 'pages/videos.html' %}
{% block content %}
{% for all_lists in videos_lists %}
<p style='text-align:center'><img src="{{ all_lists.list_cover.url }}" alt="No cover" height="450px" width="550px" ></p>
#This h2 line generating error and I dont know how to fix it.
<h2 style='text-align:center'>Title :<a href="{% url 'list_videos' all_lists.videos_lists.list_title %}"> {{ all_lists.list_title }}</a></h2> 

        <div class="date">
            <p style='text-align:center'>
                Published on: {{ all_lists.create_date|date:"D M Y" }}
            </p>
         </div> 
<br></br>
{% endfor %}
{% endblock content %}

videos/list_videos.html

代码语言:javascript
复制
{% extends 'pages/videos.html' %}
{% block content %}
<h1 style='text-align:center'>List : {{ view.kwargs.list_title }}</h1>
{% for all_videos in videos_list %}
<h2 style='text-align:center'>{{ all_videos.videos_lists }}</h2>
<p style ='text-align:center'>
<object style="height: 390px; width: 640px"><param name="movie" value=""><param name="allowFullScreen" value="true"><param name="allowScriptAccess" value="always"><embed src="{{all_videos.video_url}}" type="application/x-shockwave-flash" allowfullscreen="true" allowScriptAccess="always" width="640" height="390"></object>
</p>
<p style ='text-align:center'>
Discription :{{all_videos.discription}}
</p>
        <div class="date">
            <p style='text-align:center'>
                Published on: {{ all_videos.create_date|date:"D M Y" }}
            </p>
         </div> 
<br></br>
{% endfor %}

{% endblock content %}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-09-21 10:29:04

在您视频/videos_list.html更新<a>标记中,

代码语言:javascript
复制
<a href="{% url 'videos:list_videos' all_lists.videos_lists.list_title %}"> {{ all_lists.list_title }}</a>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63984904

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档