2
0

index.txt 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. =============================
  2. User authentication in Django
  3. =============================
  4. .. toctree::
  5. :hidden:
  6. default
  7. passwords
  8. customizing
  9. .. module:: django.contrib.auth
  10. :synopsis: Django's authentication framework.
  11. Django comes with an user authentication system. It handles user accounts,
  12. groups, permissions and cookie-based user sessions. This section of the
  13. documentation explains how the default implementation works out of the box, as
  14. well as how to :doc:`extend and customize </topics/auth/customizing>` it to
  15. suit your project's needs.
  16. Overview
  17. ========
  18. The Django authentication system handles both authentication and authorization.
  19. Briefly, authentication verifies a user is who they claim to be, and
  20. authorization determines what an authenticated user is allowed to do. Here the
  21. term authentication is used to refer to both tasks.
  22. The auth system consists of:
  23. * Users
  24. * Permissions: Binary (yes/no) flags designating whether a user may perform
  25. a certain task.
  26. * Groups: A generic way of applying labels and permissions to more than one
  27. user.
  28. * A configurable password hashing system
  29. * Forms and view tools for logging in users, or restricting content
  30. * A pluggable backend system
  31. Installation
  32. ============
  33. Authentication support is bundled as a Django contrib module in
  34. ``django.contrib.auth``. By default, the required configuration is already
  35. included in the :file:`settings.py` generated by :djadmin:`django-admin.py
  36. startproject <startproject>`, these consist of two items listed in your
  37. :setting:`INSTALLED_APPS` setting:
  38. 1. ``'django.contrib.auth'`` contains the core of the authentication framework,
  39. and its default models.
  40. 2. ``'django.contrib.contenttypes'`` is the Django :doc:`content type system
  41. </ref/contrib/contenttypes>`, which allows permissions to be associated with
  42. models you create.
  43. and two items in your :setting:`MIDDLEWARE_CLASSES` setting:
  44. 1. :class:`~django.contrib.sessions.middleware.SessionMiddleware` manages
  45. :doc:`sessions </topics/http/sessions>` across requests.
  46. 2. :class:`~django.contrib.auth.middleware.AuthenticationMiddleware` associates
  47. users with requests using sessions.
  48. With these settings in place, running the command ``manage.py syncdb`` creates
  49. the necessary database tables for auth related models, creates permissions for
  50. any models defined in your installed apps, and prompts you to create
  51. a superuser account the first time you run it.
  52. Usage
  53. =====
  54. :doc:`Using Django's default implementation <default>`
  55. * :ref:`Working with User objects <user-objects>`
  56. * :ref:`Permissions and authorization <topic-authorization>`
  57. * :ref:`Authentication in web requests <auth-web-requests>`
  58. * :ref:`Managing users in the admin <auth-admin>`
  59. :doc:`API reference for the default implementation </ref/contrib/auth>`
  60. :doc:`Customizing Users and authentication <customizing>`
  61. :doc:`Password management in Django <passwords>`