why my urls.py does't work with Django

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

Today when I code my blog with 'Building_a_blog_in_30_mins_with_Django_Screencast',I meet some problems.When I click the title with the article,it can't appear the right page.!

Page not found (404) Request Method:     GET

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

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

The current URL, app/1, didn't match any of these.

You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

and it's my urls.py:

url(r'^$',ListView.as_view(queryset=Post.objects.all().order_by("created[:2]template_name="                                                                               blog.html")),  url(r'^(?P<pk>\d+)/$',DetailView.as_view( model=Post, template_name="post.html")), url(r'^admin/', include(admin.site.urls)), url(r'^admin/doc/', include('django.contrib.admindocs.urls'))

I doesn't konw what is going on with it.Please help,thanks!

回答1:

You need to add 'app/' in your url.

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

Or may be you need to define these urls in urls.py of your app (named app ?) and include it in sites main urls.py

url(r'app/', include('app.urls'))


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!