NoReverseMatch at /videos/list/ Reverse for 'list_videos'找不到。 'list_videos'不是有效的视图函数或模式名称



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

视频/模型.py

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 

视频/视图.py

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')

videos/urls.py

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

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

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

在您的视频/videos_list.html中,像这样更新<a>标签,

<a href="{% url 'videos:list_videos' all_lists.videos_lists.list_title %}"> {{ all_lists.list_title }}</a>

最新更新