Activating the Admin Interface
时间:2010-05-05 来源:angelia_liu
Activating the Admin Interface
1. Add 'django.contrib.admin' to the INSTALLED_APPS setting.2. Make sure INSTALLED_APPS contains 'django.contrib.auth', 'django.contrib.contenttypes' and 'django.contrib.sessions'. The Django admin site requires these three packages.
3. Make sure MIDDLEWARE_CLASSES contains 'django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware' and 'django.contrib.auth.middleware.AuthenticationMiddleware'.
4. Second, run python manage.py syncdb.
This step will install the extra database tables that the admin interface uses. The first time you run syncdb with 'django.contrib.auth' in INSTALLED_APPS, you’ll be asked about creating a superuser. If you don’t do this, you’ll need to run python manage.py createsuperuser separately to create an admin user account; otherwise, you won’t be able to log in to the admin site.
5. add the admin site to your URLconf (in urls.py, remember).
By default, the urls.py generated by django-admin.py startproject contains commented-out code for the Django admin, and all you have to do is uncomment it. For the record, here are the bits you need to make sure are in there:
# Include these import statements... |
With that bit of configuration out of the way, now you can see the Django admin site in action. Just run the development server (python manage.py runserver, as in previous chapters) and visit http://127.0.0.1:8000/admin/ in your Web browser.
相关阅读 更多 +