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'/admin/login/$', 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', 'login', '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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33e4a55046b434b935418106316f8d9aafa73ef42c25f7bd7d9c23c6a46b7e8a |
|
MD5 | 9a25aff076a7f657755f6771832828db |
|
BLAKE2b-256 | a0de6d01dfb9746039209ad1a7ba92d477a239bcda051a25a6972974309c0099 |
Hashes for django_login_required_middleware-0.6.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2401f464b2aec7e91a7382f28854cffd9a4e7cb409ddc0cc63773012c7d72974 |
|
MD5 | cac67190fd50535091fb2b54aa862687 |
|
BLAKE2b-256 | 6cfb406e9a41c8401dcbba96177ebab04734d4c5e77fa40907dbe192c93603dd |