教程中的URL匹配失败(管理员)

时间:2013-02-24 16:00:18

标签: django django-models django-admin django-urls django-settings

我已经关注了Django教程第1部分,现在我正处于第2部分,我应该启动并运行管理界面。

我非常小心地按照步骤操作,但当我尝试加载网站时,我收到以下错误:

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

我首先取消注释' django.contrib.admin'在 settings.py中:

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.sites',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    # Uncomment the next line to enable the admin:
    'django.contrib.admin',
    # Uncomment the next line to enable admin documentation:
    # 'django.contrib.admindocs',
    'polls',
)

...之后我运行 python manage.py syncdb ,输出:

Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)

...然后我根据教程在 urls.py:

中取消注释我应该使用的三行
from django.conf.urls import patterns, include, url

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

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

    # Uncomment the admin/doc line below to enable admin documentation:
    # url(r'^admin/doc/', include('django.contrib.admindocs.urls')),

    # Uncomment the next line to enable the admin:
    url(r'^admin/', include(admin.site.urls)),
)

如上所述,如果运行,会生成错误消息。

有什么不对?我的意思是我按照假设完全按照教程。

1 个答案:

答案 0 :(得分:2)

请注意教程中的说明:

  

现在,打开一个Web浏览器并转到您本地域的“/ admin /” - 例如http://127.0.0.1:8000/admin/

添加错误显示,您尝试转到根网址,而不是按指示转到/admin/