Skip to content

django-clearance

Role, policy and row-level access control for Django. Denied by default.

An administrator decides, in Django's admin site and with no code, who may do what - and to which rows, and with which fields.

A row scope built in the admin site, with no code: the orders whose status is pending or approved

  • Bundles of permissions, each given with a scope - "their branch's orders", "their own", or a rule built in the admin site.
  • Protected fields, read with one permission and written with another.
  • Status actions - only whoever may approve sets an order to approved.
  • Roles, optional, with a ceiling nobody with the role goes past.

Every door asks the same rules: Django's views and templates, DRF, the admin site, and your own code. A change is refused when it would let somebody give themselves more. The pages, messages and permissions come in English and Persian.

Install

pip install django-clearance            # with Django's views and admin site
pip install 'django-clearance[drf]'     # and Django REST framework
INSTALLED_APPS = [
    'clearance.admin.apps.ClearanceAdminConfig',   # instead of 'django.contrib.admin'
    ...
    'clearance',
]

AUTHENTICATION_BACKENDS = ['clearance.backends.ClearanceBackend']

Where to go next

Getting started what it is for, installing it, and a first bundle in a few lines
The tutorial the example shop, built a layer at a time
The admin panel every access page, with pictures
How-to guides one question a project meets, answered in a few steps
The reference every setting, check, command, signal and model - and the Python API
The guide every part of the library, and how to use it
Explanation and the design why it is built the way it is
Questions what people ask first
Contributing, security, versions working on it, reporting a problem, what it runs on
The changelog what each release changed
The example shop a project using all of it, to run

Python 3.11 to 3.14; Django 5.2, 6.0 and 6.1; Django REST framework 3.16 and later, optional; any database Django supports.