Search code examples
pythondjangoauthenticationbasic-authenticationhttp-authentication

Django: Basic Auth for one view (avoid middleware)


I need to provide http-basic-auth to one view.

I want to avoid modifying the middleware settings.

Background: This is a view which gets filled in by a remote application.


Solution

  • This library could be used: https://github.com/hirokiky/django-basicauth

    Basic auth utilities for Django.

    The docs show how to use it:

    Applying decorator to CBVs

    To apply @basic_auth_requried decorator to Class Based Views, use django.utils.decorators.method_decorator.

    Source: https://github.com/hirokiky/django-basicauth#applying-decorator-to-cbvs