Django教程1.0中第六章的Admin管理页面问题

这个问题恐怕只有看那个教程的人们会遇到

因为教程和实际安装的Django版本不同所以造成的

解决方法参考了官方文档:

https://docs.djangoproject.com/en/dev/intro/tutorial02/

大家如果是一步步照着教程做的,那么代码应该类似这样:

#mysite.urls

from django.conf.urls.defaults import patterns, include, url  
from mysite.views import current_datetime,hours_ahead

urlpatterns = patterns('',  
                       (r'^time/$', current_datetime),
                       (r'^time/plus/(d{1,2})/$',hours_ahead),
)
#mysite.settings

MIDDLEWARE_CLASSES = (  
    #'django.middleware.common.CommonMiddleware',
    #'django.contrib.sessions.middleware.SessionMiddleware',
    #'django.middleware.csrf.CsrfViewMiddleware',
    #'django.contrib.auth.middleware.AuthenticationMiddleware',
    #'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATE_DIRS = ('templates',  
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

INSTALLED_APPS = (  
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    #'django.contrib.sites',
    #'django.contrib.messages',
    #'django.contrib.staticfiles',
    'mysite.books',
    'django.contrib.admin',
    'django.contrib.admindocs',
)

我们将它修改成这样:

#mysite.urls

from django.conf.urls.defaults import patterns, include, url  
from mysite.views import current_datetime,hours_ahead  
from django.conf.urls.defaults import *  
# Uncomment the next two lines to enable the admin:
from django.contrib import admin  
admin.autodiscover()

urlpatterns = patterns('',  
                       (r'^time/$', current_datetime),
                       (r'^time/plus/(d{1,2})/$',hours_ahead),
    # 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
    url(r'^admin/', include(admin.site.urls)),
)
#mysite.settings

MIDDLEWARE_CLASSES = (  
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
)

ROOT_URLCONF = 'mysite.urls'

TEMPLATE_DIRS = ('templates',  
    # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
    # Always use forward slashes, even on Windows.
    # Don't forget to use absolute paths, not relative paths.
)

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

可以很明显的看出,我将注释都去除掉了

接下来在命令行中:

python manage.py syncdb  
python manage.py runserver  

再打开http://127.0.0.1:8000/admin/就是admin页面了

在教程译文的注释中我也进行了说明.