Skip to main content

Basic Usage

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!

Metadata

Release files for custom-user-roles 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for custom-user-roles 1.1.0
File Size Uploaded Provenance Actions
custom-user-roles-1.1.0.tar.gz 4.6 kB Without provenance Details for custom-user-roles-1.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for custom-user-roles 1.1.0
File Interpreter ABI Platform Actions
custom_user_roles-1.1.0-py2-none-any.whl Python 2 none any Details for custom_user_roles-1.1.0-py2-none-any.whl

Total release size: 12.1 kB

Release files / custom-user-roles-1.1.0.tar.gz

Download URL custom-user-roles-1.1.0.tar.gz
Size 4.6 kB
Tags Source
SHA-256 checksum
How to use checksums
6d995563f8fe5c6d3167687af65cceae54a4e603057b20541dc8352541a2615a
BLAKE2b-256 checksum
How to use checksums
4f34b5c3d04001078ded898e0a5daeb12237316b693c4080f184da8cd34d5c8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / custom_user_roles-1.1.0-py2-none-any.whl

Download URL custom_user_roles-1.1.0-py2-none-any.whl
Size 7.5 kB
Tags Python 2
SHA-256 checksum
How to use checksums
b6b2bdb1522686891596205a4b33e23f7f6452bc4c7a279220b632808896d13a
BLAKE2b-256 checksum
How to use checksums
fb3a17c2a3b91a2303745656c6b21e31e4dfa296d22f4e12656f29da22b06897
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for custom-user-roles 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

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