urlpattern保持重定向到404

时间:2018-05-01 15:31:59

标签: django url

我遵循标准从here在Django中构建您的第一个博客Web应用程序。我试图通过使用此代码从URL获取博客的索引值来显示单独的页面。

from django.conf.urls import url, include
from django.urls import path
from django.views.generic import ListView, DetailView
from .models import Post
from .views import blogindex


urlpatterns = [
    path('', ListView.as_view(
        queryset = Post.objects.all().order_by("-date")[:25], 
        template_name="blog/blog.html"
    )),

    path(r'^(?P<pk>\d+)$', DetailView.as_view(
            model = Post,
            template_name = "blog/post.html")),
]

每次我去URL localhost / blog / 2它只是给我404找不到。

Using the URLconf defined in mysite.urls, Django tried these URL patterns, in this order:

    admin/
    ^$
    ^blog
    ^blog ^(?P<pk>\d+)$

The current path, blog/2, didn't match any of these.

main urls.py

urlpatterns = [
    path('admin/', admin.site.urls),
    url('^$', include('home.urls')),
    url('^blog', include('blog.urls'))
]

0 个答案:

没有答案