找不到Django博客页面(404)-没有帖子与给定查询匹配

时间:2019-07-28 12:43:49

标签: python django view

我正在用Django编写博客,单击地址http://localhost:8000/blog/2019/7/28/prim-algorithm-path时出现错误404 没有帖子匹配给定的查询。提出者:blog.views.blog_detail

views.py

def blog_detail(request,year,month,day,post):
    print(year,month,day,post)
    post = get_object_or_404(Post, slug=post, publish__year=year, publish__month=month,publish__day=day)
    return render(request,'post.html',locals())

blog / urls.py

from django.urls import path
from .views import index,blog_detail
app_name = 'blog'
urlpatterns = [
    path('', index, name='index'),
    path('<int:year>/<int:month>/<int:day>/<slug:post>',blog_detail,name='post_detail'),

]

mysite / urls.py

from django.contrib import admin
from django.urls import path,include


urlpatterns = [
    path('admin/', admin.site.urls),
    path('blog/',include('blog.urls',namespace='blog')),
]

0 个答案:

没有答案