0

我遵循了 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.

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

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)),
)

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

有什么问题?我的意思是我完全按照本教程进行了操作。

4

1 回答 1

2

请注意教程中的说明:

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

添加错误显示,您正在尝试转到根 URL,而不是/admin/按照指示。

于 2013-02-24T16:30:25.123 回答