【发布时间】:2019-11-25 00:56:06
【问题描述】:
当我单击菜单中的类别链接时,出现以下错误。
找不到页面 (404)
请求方法:GET
请求网址:http://127.0.0.1:8000/post/categorylist/
提出者:post.views.post_detail
没有帖子匹配给定的查询。
models.py
def get_categorylist_url(self):
return reverse('post:categorylist', kwargs={'slug': self.slug})
views.py
def post_categorylist(request, slug):
if not request.user.is_superuser:
raise Http404()
post = get_object_or_404(Post, slug=slug)
post.categorylist()
return redirect('post:categorylist')
urls.py
path('categorylist/',views.post_categorylist, name='categorylist'),
header.html
<li><a href="{% url 'post:categorylist' %}">Kategoriler</a></li>
categorylist.html
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
Test message.
</body>
</html>
【问题讨论】: