Skip to main content

Requires login to all requests through middleware.

Project description

django-login-required-middleware

Tests Coverage Status PyPI Version PyPI downloads

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

  1. Install pip install django-login-required-middleware

  2. Add login_required.middleware.LoginRequiredMiddleware to MIDDLEWARE after django.contrib.auth.middleware.AuthenticationMiddleware

  3. (Optional) To ignore authentication in a view uses decorato @login_not_required for FBV or LoginNotRequiredMixin 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()
    
  4. (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/$'
    ]
    
  5. (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


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

File details

Details for the file django-login-required-middleware-0.6.0.tar.gz.

File metadata

  • Download URL: django-login-required-middleware-0.6.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for django-login-required-middleware-0.6.0.tar.gz
Algorithm Hash digest
SHA256 6d1ace6e645dcbf778fadc0b3bc0470cc7dcf2e70e91fc4f31725a43b8549fc4
MD5 97e3320e34cbbcff1141689f551c43ea
BLAKE2b-256 a78e7e40803b8fb3c4b0b7ec3418e12a5a76c99d4aaf869f4445f330f3db69fb

See more details on using hashes here.

File details

Details for the file django_login_required_middleware-0.6.0-py3-none-any.whl.

File metadata

  • Download URL: django_login_required_middleware-0.6.0-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.58.0 CPython/3.9.2

File hashes

Hashes for django_login_required_middleware-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97c41139d6998c682ffd897ad952bce7ef0680f1bbc87f3e4f2f9bb4b5ff1330
MD5 73025542ba9d381d79cb8f293a3d6de3
BLAKE2b-256 e9ac25aedb5aa1ea155f8b16b74098407258be8d799fb5d5b89e50f6eb195771

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page