Django框架中的使用者認證的實現

jieforest發表於2012-12-09
Django comes with a user authentication system. It handles user accounts, groups, permissions and cookie-based user sessions. This document explains how things work.

Overview
The auth system consists of:

1. Users
2. Permissions: Binary (yes/no) flags designating whether a user may perform. a certain task.
3. Groups: A generic way of applying labels and permissions to more than one user.

Installation
Authentication support is bundled as a Django application in django.contrib.auth. To install it, do the following:

1. Put 'django.contrib.auth' and 'django.contrib.contenttypes' in your INSTALLED_APPS setting. (The Permission model indjango.contrib.auth depends on django.contrib.contenttypes.)
2. Run the command manage.py syncdb.

Note that the default settings.py file created by django-admin.py startproject includes 'django.contrib.auth' and'django.contrib.contenttypes' in INSTALLED_APPS for convenience. If your INSTALLED_APPS already contains these apps, feel free to run manage.py syncdb again; you can run that command as many times as you’d like, and each time it’ll only install what’s needed.

The syncdb command creates the necessary database tables, creates permission objects for all installed apps that need ‘em, and prompts you to create a superuser account the first time you run it.

Once you’ve taken those steps, that’s it.

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-750802/,如需轉載,請註明出處,否則將追究法律責任。

相關文章