django-login-required-middleware
django-login-required-middleware provide login to all requests through middleware.
If the website has many views and almost all use
LoginRequiredMixin or the login_required decorator, using django-login-required
can keep the code of your views more clear and avoids forgetting authentication of view.
Requirements
- Python 3.8 to 3.10 supported.
- Django 3.2 to 4.1 supported.
Quick start
-
Install
pip install django-login-required-middleware -
Add
login_required.middleware.LoginRequiredMiddlewaretoMIDDLEWAREafterdjango.contrib.auth.middleware.AuthenticationMiddleware -
(Optional) To ignore authentication in a view uses decorato
@login_not_requiredfor FBV orLoginNotRequiredMixinfor CBV:from login_required import login_not_required @login_not_required def my_view(request): return HttpResponse()
or
from login_required import LoginNotRequiredMixin class MyView(LoginNotRequiredMixin, View): def get(self, request, *args, **kwargs): return HttpResponse()
-
(Optional) Add
LOGIN_REQUIRED_IGNORE_PATHSsetting. Any requests which match these paths will be ignored. This setting should be a list filled with regex paths (settings.LOGIN_URLalways included).Example:
LOGIN_REQUIRED_IGNORE_PATHS = [ r'/accounts/logout/$', r'/accounts/signup/$', r'/admin/$', r'/about/$' ]
-
(Optional) Add
LOGIN_REQUIRED_IGNORE_VIEW_NAMESsetting. Any requests which match these url name will be ignored. This setting should be a list filled with url names.Example:
LOGIN_REQUIRED_IGNORE_VIEW_NAMES = [ 'home', 'admin:index', 'admin:login', 'namespace:url_name', ]
-
(Optional) Add
LOGIN_REQUIRED_REDIRECT_FIELD_NAMEsetting. This will be passed to Django's redirect_to_login(). Default is 'next'.Example:
LOGIN_REQUIRED_REDIRECT_FIELD_NAME = 'next_url'
Metadata
Release files for django-login-required-middleware 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-login-required-middleware-0.9.0.tar.gz | 4.5 kB | Without provenance | Details |
Release files / django-login-required-middleware-0.9.0.tar.gz
| Download URL | django-login-required-middleware-0.9.0.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
847ae9a69fd7a07618ed53192b3c06946af70a0caf6d0f4eb40a8f37593cd970
|
|
BLAKE2b-256 checksum How to use checksums |
ef51edb065f2f24c46d5c17633080b91b3817d1b890d4f0924c36d338e9e125f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Security for django-login-required-middleware 0.9.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.