Django:urls.py中的404错误

时间:2011-10-15 13:22:21

标签: django django-urls

我有两个urls.py个文件。

project/urls.py

from django.conf.urls.defaults import *

from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
    (r'^/', include('blog.urls')),
    url(r'^admin/', include(admin.site.urls)),
)

project/blog/urls.py

from django.conf.urls.defaults import *

urlpatterns = patterns('blog.views',
    (r'^$', 'index'),
    (r'^(?P<slug>[a-z-]+)/$', 'detail'),
    (r'^(?P<slug>[a-z-]+)/comment/$', 'comment'),
)

然后我尝试浏览这些网址:

http://127.0.0.1:8888/ (404)

http://127.0.0.1:8888/hello-world/ (404)

http://127.0.0.1:8888/admin/ (It worked)

Django版本:1.4 pre-alpha SVN-16985

谢谢!

1 个答案:

答案 0 :(得分:0)

要解决http://127.0.0.1:8888/错误,请将正则表达式更改为:

(r'^$', include('blog.urls')),

关于http://127.0.0.1:8888/hello-world/错误:可能有很多原因造成这种情况。首先,检查你是否有一个博客标题实际上返回了slug'hello-world'。