-2

我是 Django 1.4.2 的新手用户。我已经玩了几个星期,但我一直卡在同一点:如果我转到预设的网址,则会出现 404 ......

URLS.PY:

from django.conf.urls.defaults import *
from django.contrib import admin
from django.conf import settings

admin.autodiscover()

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    url(r'^', include('cms.urls')),
    (r'^comments/', include('django.contrib.comments.urls')),
)

if settings.DEBUG:
    urlpatterns = patterns('',
    url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
    {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}),
    url(r'', include('django.contrib.staticfiles.urls')),
) + urlpatterns    # Example:

我已经多次关注 Django CMS 和其他一些插件,但是当我想预览一个 url 时,我一直收到 404 错误。在这种情况下,我已经成功安装了 Django 评论,我可以创建评论(在后端),但如果我想在前端预览它们...404。我的 URLS.PY 有问题吗?

example.com/en/comments -> 404

提前致谢。

4

2 回答 2

0

Did you try:

urlpatterns = patterns('',
    (r'^admin/', include(admin.site.urls)),
    (r'^comments/', include('django.contrib.comments.urls')),
    url(r'^', include('cms.urls')),
)

?

'example.com/comments/' should work. If you get the same error make sure you have 'django.contrib.comments' added to INSTALLED_APPS in your settings.py file. You may also run 'manage.py syncdb' in order for the tables related to the 'comments' app to be created.

Where the 'en/' comes from anyway? Is it a hard-coded URL in your app page or is it inserted by you manually?

于 2012-10-26T14:27:21.577 回答
0

简单的问题:您在 URL conf 中的任何地方看到en或类似的东西吗?(?P<language>...)那你为什么期望你会得到除了 404 之外的任何东西/en/comments/

此外,在 (root) 处包含 Django CMS url^$本质上会将所有 URL 处理传递给它的 urls.py,因此在此之后添加到 urls.py 的任何内容都将被忽略。如果你想包含别的东西,它必须在 urls.py之前,然后它将在你指定的 urlpattern 中可用,在这种情况下,只是/comments/,不是/en/comments/

于 2012-10-26T13:10:05.900 回答