【问题标题】:Django: when trying domain.com/admin gives 404 with an old unexisting urls fileDjango:在尝试 domain.com/admin 时会给出 404 和旧的不存在的 urls 文件
【发布时间】:2011-05-16 14:19:16
【问题描述】:

我曾经有一个 urls 文件看起来像这样:

# Uncomment the next two lines to enable the admin:
from django.contrib import admin
admin.autodiscover()

urlpatterns = patterns('',
# Example:
url(r'^$', 'girls.views.home', name = 'home'),
url(r'^registerasboy$', 'girls.views.regb', name= 'regb'), 
#url(r'^registerasgirl$', 'girls.views.reg', name= 'regg'),
url(r'^thankyou$', 'girls.views.thankyou', name= 'thankyou'),
url(r'^newchick$', 'girls.views.newchick', name= 'newchick'),
url(r'^chicks$', 'girls.views.chicks', name= 'chicks'),
#url(r'^thankyou$', 'generalsettings.views.thankyou', name = 'thankyou'),
# Uncomment the admin/doc line below to enable admin documentation:
# (r'^admin/doc/', include('django.contrib.admindocs.urls')),
#url(r'^reg$', 'generalsettings.views.home'),
# Uncomment the next line to enable the admin:
#(r'^admin/', include(admin.site.urls)),
#(r'^media/(?P<path>.*)$', 'django.views.static.serve', {'document_root':     settings.MEDIA_ROOT}),
)

并且该网站有效。我没有管理员。所以我决定取消注释管理行,我会得到错误 404

找不到页面 (404)
请求方法:GET
请求网址:http://chicklister.com/admin

Using the URLconf defined in chick.urls, Django tried these URL patterns,
in this order:
^$ [name='home']
^registerasboy$ [name='regb']
^thankyou$ [name='thankyou']
^newchick$ [name='newchick']
^chicks$ [name='chicks']
^/(?P<path>.*)$
The current URL, admin, didn't match any of these.

这很奇怪,因为这里缺少管理行。现在,我将我的网址进一步更新为:

urlpatterns = 模式('',
(r'^admin/', 包括(admin.site.urls)),)

但我得到了管理员:

Using the URLconf defined in chick.urls, Django tried these URL patterns,
in this order:
^$ [name='home']
^registerasboy$ [name='regb']
^thankyou$ [name='thankyou']
^newchick$ [name='newchick']
^chicks$ [name='chicks']
^/(?P<path>.*)$
The current URL, admin, didn't match any of these.

然而,根据打印的 url 文件中的行,任何其他 url 都可以使用,例如 www.domain.com/thankyou

这怎么可能?好像在什么地方被记住了。

我做的步骤: 在 www 中的整个文件夹中搜索“registerasboy”并不再返回任何内容。 我更改了模板上的文本,以确保我正在更新正确的副本。 我在 settings.py 中有以下设置:

ROOT_URLCONF = '网址' 我注意到它并没有真正做任何事情,因为一开始它是chic.urls

我做错了什么?我似乎连这样的文件都没有了……

【问题讨论】:

    标签: python django url settings


    【解决方案1】:

    只是在黑暗中拍摄:

    您是否在 INSTALLED_APPS 中添加了管理员,执行了同步数据库并重新启动了服务器?

    如果您将 Apache 与 mod_wsgi 一起使用,则重新启动服务器很有用。它不会检测代码中的更改,因此您需要手动重新加载它。

    开发服务器自动重新加载代码。

    以下是有关此问题的完整信息: http://code.google.com/p/modwsgi/wiki/ReloadingSourceCode

    【讨论】:

    • 它在我安装的应用程序中,是的。
    • 我刚刚重新启动了 apache,它工作了。诡异的。我必须多久重新启动一次apache?每次我有新的更新?
    • 是的,这是我最近遇到的一个问题。我认为开发服务器会自动重新加载它,但 mod_WSGI 不会。这是因为 Django 进程仍然存在并且代码已经加载。遇到此类问题时,请务必尝试重新启动。
    • 感谢您的回答。我在问题中添加了原因,以便其他人可以轻松查看。
    • 如果您有兴趣,我还添加了包含完整信息的链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-12
    • 2016-03-30
    • 2020-08-06
    • 2012-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多