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.6.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a2ba8816b2a3f2bd5512a44b91e5cd8c87861baa6f3f3f49bb1f63af732585b |
|
MD5 | 0e4fc83ba1d29f7c144a901323641748 |
|
BLAKE2b-256 | aea0b51daf65822399b83d53a40b22a16be4aed8bda324fafbe2c5ce725b3892 |
Hashes for django_login_required_middleware-0.6.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97c099e22281c225c7ab068491e8157f2ad5c6df6fe76b2c53e82822b546e2ae |
|
MD5 | 6f2529203ca93acc9767453ed56ee515 |
|
BLAKE2b-256 | 4c8bc4ff24eabb0d497304b20bd50e962f6ac8285391b4182905564a1f3008cb |