【问题标题】:Django URLconf changes itself strangelyDjango URLconf 奇怪地改变了自己
【发布时间】:2014-07-03 11:58:21
【问题描述】:

这是我的 urls.py 文件:

urlpatterns = patterns('',
# Examples:
# url(r'^$', 'halo.views.home', name='home'),
# url(r'^blog/', include('blog.urls')),

url(r'^halo/admin/', include(admin.site.urls)),                            
)

大多数时候,我可以访问 example.com/halo/admin。但有时,它会显示 404 错误:

Using the URLconf defined in halo.urls, Django tried these URL patterns, in this order:
$admin/
The current URL, halo/admin/, didn't match any of these.

这很奇怪,因为我的 urls.py 中没有'$admin/'。

【问题讨论】:

  • 您应该记住,django/python 或任何类型的编程语言都不能改变或修改自己。问题在于您的代码。根据您的代码,您必须使用 xxx.com/halo/admin/ 访问管理站点,因此使用 xxx.com/halo/admin 在这里没有帮助。 Urlconfig 无法自行更改。
  • 我知道。但是,如何解释错误页面显示的原因:$admin/ 当前的 URL,halo/admin/,与这些都不匹配。
  • 请将您传递的网址复制粘贴到浏览器中。

标签: django admin django-urls


【解决方案1】:

您在浏览器中点击了错误的网址。

例如:

http://example.com//halo/admin/

在这里传递 // 在 url 中可能会产生您面临的同样问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-19
    • 2019-08-10
    • 2013-06-01
    • 1970-01-01
    • 2011-05-26
    • 1970-01-01
    • 2022-01-06
    • 1970-01-01
    相关资源
    最近更新 更多