Python django中未找到slug 404
这是我的观点Python django中未找到slug 404,python,django,Python,Django,这是我的观点 from .models import Post,Author def posts_list(request): all_posts = Post.objects.all() context = { 'all_posts': all_posts } return render(request,"post_list.html",context) def posts_detail(request, slug): unique_post
from .models import Post,Author
def posts_list(request):
all_posts = Post.objects.all()
context = {
'all_posts': all_posts
}
return render(request,"post_list.html",context)
def posts_detail(request, slug):
unique_post = get_object_or_404(Post, slug=slug)
context = {
'post': unique_post,
}
return render(request,"posts_detail.html",context)
我的URL.py是:
from django.urls import path
from posts import views
urlpatterns = [
path('admin/', admin.site.urls),
path('post/',views.posts_list),
path('post/(<slug:slug>/', views.posts_detail,name='post'),
]
从django.url导入路径
从帖子导入视图
URL模式=[
路径('admin/',admin.site.url),
路径('post/',views.posts_列表),
路径('post/(/',views.posts_detail,name='post'),
]
每次我去
我得到404页面未找到我厌倦了重新加载django服务器,也找到了其他解决方案,但我无法找出路由上的问题是什么,但在slug不工作后,请帮助我解决此问题。删除括号(
在slug
之前
改变这个
path('post/(<slug:slug>/', views.posts_detail,name='post'),
path('post/(/',views.posts\u detail,name='post'),
到
path('post/',views.posts\u detail,name='post'),
谢谢path('post/',views.posts_detail,name='post'),请在删除前删除括号slug@bmons哦,我犯了个愚蠢的错误,但我还是不明白,谢谢你
path('post/<slug:slug>/', views.posts_detail,name='post'),