Skip to main content

AuthMiddleware

A Django middleware to enforce user login before accessing certain views.

image

image

Setup

You can install django-authmiddleware from pip using

pip install django-authmiddleware

and then add it to your middleware using:

MIDDLEWARE = [
    ...
    'AuthMiddleware.middleware.AuthRequiredMiddleware',
    ...
]

Make sure you add the trailing comma or you might get a ImproperlyConfigured Exception.

Configuration

Configure the middleware's behaviour in your Django project's settings. The middleware expects a AUTH_SETTINGS setting within Django settings to work properly. You must set the following keys within AUTH_SETTINGS:

  • LOGIN_URL
  • DEFAULT_REDIRECT_URL
  • LOCK_URLS
  • REDIRECT_AFTER_LOGIN

LOGIN_URL

A URL name that is used for login in your django project. Defaults to login.

AUTH_SETTINGS = {
    ...
    "LOGIN_URL" : "example"
    ...
}

DEFAULT_REDIRECT_URL

A URL name to which users are redirect if they try to access an invalid URLs. Defaults to None.

When set to None, no redirects take place and error is generated for invalid URLs.

AUTH_SETTINGS = {
    ...
    "DEFAULT_REDIRECT_URL" : "example"
    ...
}

LOCK_URLS

A set of URL names to which access is restricted. Access to these URLs is given only on successful login. Default to empty set {}.

AUTH_SETTINGS = {
    ...
    "LOCK_URLS" : {
        "example-1",
        "example-2",
        "example-3",
        ...
        }
    ...
}

REDIRECT_AFTER_LOGIN

If set to True, user is redirected to original page after successful login. Adds ?next parameter to URL request. Defaults to True.

AUTH_SETTINGS = {
    ...
    "REDIRECT_AFTER_LOGIN" : False,
    ...
}

Contributing

Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Release files for django-authmiddleware 0.0.4

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

Source distribution (sdist)

Source distribution for django-authmiddleware 0.0.4
File Size Uploaded
django_authmiddleware-0.0.4.tar.gz 3.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-authmiddleware 0.0.4
File Interpreter ABI Platform
django_authmiddleware-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 7.9 kB

Release files / django_authmiddleware-0.0.4.tar.gz

Download URL django_authmiddleware-0.0.4.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
031e0358f5e3182a177288f191b7190f667a5d4ae224feb72730052fc2fc38a1
BLAKE2b-256 checksum
How to use checksums
b0b3a03961d1b53bb89a53a728d19260aa0204d7ca6037489702a66f532d7a11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release files / django_authmiddleware-0.0.4-py3-none-any.whl

Download URL django_authmiddleware-0.0.4-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e1cc668279da33fc33ad97a5c68ceb166647612fa30f288919b4f75473453644
BLAKE2b-256 checksum
How to use checksums
ac31b5be324e8d5eb4ce5bb16c26e9cbf85cff01c068cf02d780f5f705356635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release 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