Requires login to all requests through middleware.
Project description
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.6, 3.7, 3.8
- Django: 1.11, 2.0, 2.1, 2.2, 3.0x
Quick start
-
Install
pip install django-login-required-middleware
-
Add
login_required.middleware.LoginRequiredMiddleware
toMIDDLEWARE
afterdjango.contrib.auth.middleware.AuthenticationMiddleware
-
(Optional) To ignore authentication in a view uses decorato
@login_not_required
for FBV orLoginNotRequiredMixin
for 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_PATHS
setting. Any requests which match these paths will be ignored. This setting should be a list filled with regex paths (settings.LOGIN_URL
always included).Example:
LOGIN_REQUIRED_IGNORE_PATHS = [ r'/accounts/logout/$' r'/accounts/signup/$', r'/admin/$', r'/about/$' ]
-
(Optional) Add
LOGIN_REQUIRED_IGNORE_VIEW_NAMES
setting. 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', ]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-login-required-middleware-0.7.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4be6ba85c111cb62d710754f8bb60017f1bb4a18e55342f360535141cb65de2e |
|
MD5 | a6bb06148a9c2bcca02d9f992bb8566f |
|
BLAKE2b-256 | 91e1f42c3aab07dd7d5db3b148ea75f288493e7db33ff4e91dfb34e57a598636 |
Hashes for django_login_required_middleware-0.7.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0c7aad9ee748db0227dbf4f1dff7a6a7f0f3c69aa76ed240474579b88b63a41e |
|
MD5 | c920850303de63a4a69f0945d4bba0ec |
|
BLAKE2b-256 | 07f2f0ff7bedfe5d12e392795acc8d47f3e189e66ba11b003e958b3f3e4a871d |