Django:urls.py 中出现 404 错误
我有两个 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'),
)
然后我尝试浏览这些 URL:
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。
谢谢!
I have two urls.py
files.
In 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)),
)
In project/blog/urls.py
:
from django.conf.urls.defaults import *
urlpatterns = patterns('blog.views',
(r'^
Then I tried to browse these URLs:
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 version: 1.4 pre-alpha SVN-16985
.
Thanks!
, 'index'),
(r'^(?P<slug>[a-z-]+)/
Then I tried to browse these URLs:
Django version: 1.4 pre-alpha SVN-16985
.
Thanks!
, 'detail'),
(r'^(?P<slug>[a-z-]+)/comment/
Then I tried to browse these URLs:
Django version: 1.4 pre-alpha SVN-16985
.
Thanks!
, 'comment'),
)
Then I tried to browse these URLs:
Django version: 1.4 pre-alpha SVN-16985
.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要修复 http://127.0.0.1:8888/ 错误,请将正则表达式更改为
: a href="http://127.0.0.1:8888/hello-world/" rel="nofollow">http://127.0.0.1:8888/hello-world/ 错误:可能有很多原因导致此问题。首先,检查您的博客标题是否实际返回 slug“hello-world”。
To fix the http://127.0.0.1:8888/ error, change your regular expression to:
Regarding the http://127.0.0.1:8888/hello-world/ error: There could be many things causing this. First, check that you have a blog title that actually returns the slug 'hello-world'.