Django:urls.py 中出现 404 错误

发布于 2024-12-10 05:29:45 字数 808 浏览 0 评论 0原文

我有两个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄情伤 2024-12-17 05:29:45

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

(r'^

: a href="http://127.0.0.1:8888/hello-world/" rel="nofollow">http://127.0.0.1:8888/hello-world/ 错误:可能有很多原因导致此问题。首先,检查您的博客标题是否实际返回 slug“hello-world”。

, include('blog.urls')),

: 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:

(r'^

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'.

, include('blog.urls')),

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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文