Giter Site home page Giter Site logo

mgogoulos / django-login-required-middleware Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cleitondelima/django-login-required-middleware

1.0 1.0 0.0 55 KB

Requires login to all requests through middleware.

License: MIT License

Makefile 2.57% Python 97.43%

django-login-required-middleware's Introduction

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.

    Example:

    LOGIN_REQUIRED_IGNORE_PATHS = [
        r'/accounts/login/$',
        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',
    ]

django-login-required-middleware's People

Contributors

andylolz avatar bgeneto avatar cleitondelima avatar danishabsar avatar dependabot-preview[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.