Skip to main content

Add userroles do INSTALLED_APPS

INSTALLED_APPS = (
    ...
    'userroles',
)

Add the USER_ROLES setting

USER_ROLES = (
    'manager',
    'moderator',
    'client',
)

Define your Custom User model (optional)

AUTH_USER_MODEL = 'custom_user.EmailUser'

Add subroles for any of the roles defined in the USER_ROLES setting (optional)

MANAGER_ROLES = (
    'staff_manager', 'business_manager'
)

Subroles can have sub-subroles and so on. But be careful not to repeat the names!

The role_required decorator provides similar behavior to Django’s login_required and permission_required decorators. If the user accessing the view does not have the required roles, they will be redirected to the login page.

from userroles.decorators import role_required

@role_required('manager', 'moderator')
def view(request):
    ...

or

from userroles.decorators import role_required
from userroles import roles

@role_required(roles.manager, roles.moderator)
def view(request):
    ...

If user has a subrole of the required role, it passes de user test as well!

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

custom-user-roles-1.1.0.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

custom_user_roles-1.1.0-py2-none-any.whl (7.5 kB view details)

Uploaded Python 2

File details

Details for the file custom-user-roles-1.1.0.tar.gz.

File metadata

File hashes

Hashes for custom-user-roles-1.1.0.tar.gz
Algorithm Hash digest
SHA256 6d995563f8fe5c6d3167687af65cceae54a4e603057b20541dc8352541a2615a
MD5 85721fdc669e2698808f95949a0dd00f
BLAKE2b-256 4f34b5c3d04001078ded898e0a5daeb12237316b693c4080f184da8cd34d5c8d

See more details on using hashes here.

File details

Details for the file custom_user_roles-1.1.0-py2-none-any.whl.

File metadata

File hashes

Hashes for custom_user_roles-1.1.0-py2-none-any.whl
Algorithm Hash digest
SHA256 b6b2bdb1522686891596205a4b33e23f7f6452bc4c7a279220b632808896d13a
MD5 b30b3982105b4d45f538dc7416e95a01
BLAKE2b-256 fb3a17c2a3b91a2303745656c6b21e31e4dfa296d22f4e12656f29da22b06897

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page