Django (2024)

Table of Contents
Overview¶ Installation¶ Usage¶

Django comes with a user authentication system. It handles user accounts,groups, permissions and cookie-based user sessions. This section of thedocumentation explains how the default implementation works out of the box, aswell as how to extend and customize it tosuit your project’s needs.

Overview

The Django authentication system handles both authentication and authorization.Briefly, authentication verifies a user is who they claim to be, andauthorization determines what an authenticated user is allowed to do. Here theterm authentication is used to refer to both tasks.

The auth system consists of:

  • Users
  • Permissions: Binary (yes/no) flags designating whether a user may performa certain task.
  • Groups: A generic way of applying labels and permissions to more than oneuser.
  • A configurable password hashing system
  • Forms and view tools for logging in users, or restricting content
  • A pluggable backend system

The authentication system in Django aims to be very generic and doesn’t providesome features commonly found in web authentication systems. Solutions for someof these common problems have been implemented in third-party packages:

  • Password strength checking
  • Throttling of login attempts
  • Authentication against third-parties (OAuth, for example)
  • Object-level permissions

Installation

Authentication support is bundled as a Django contrib module indjango.contrib.auth. By default, the required configuration is alreadyincluded in the settings.py generated by django-adminstartproject, these consist of two items listed in yourINSTALLED_APPS setting:

  1. 'django.contrib.auth' contains the core of the authentication framework,and its default models.
  2. 'django.contrib.contenttypes' is the Django content type system, which allows permissions to be associated withmodels you create.

and these items in your MIDDLEWARE setting:

  1. SessionMiddleware managessessions across requests.
  2. AuthenticationMiddleware associatesusers with requests using sessions.

With these settings in place, running the command manage.py migrate createsthe necessary database tables for auth related models and permissions for anymodels defined in your installed apps.

Django (2024)
Top Articles
Latest Posts
Article information

Author: Greg Kuvalis

Last Updated:

Views: 5836

Rating: 4.4 / 5 (55 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Greg Kuvalis

Birthday: 1996-12-20

Address: 53157 Trantow Inlet, Townemouth, FL 92564-0267

Phone: +68218650356656

Job: IT Representative

Hobby: Knitting, Amateur radio, Skiing, Running, Mountain biking, Slacklining, Electronics

Introduction: My name is Greg Kuvalis, I am a witty, spotless, beautiful, charming, delightful, thankful, beautiful person who loves writing and wants to share my knowledge and understanding with you.