问题
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'))
来源:https://stackoverflow.com/questions/12766889/why-my-urls-py-doest-work-with-django