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 fil
For those that already use django-rest-framework (DRF):
DRF has a BasicAuthentication
class which, more-or-less, does what is described in the other answers (see source).
This class can also be used in "normal" Django views.
For example:
from rest_framework.authentication import BasicAuthentication
def my_view(request):
# use django-rest-framework's basic authentication to get user
user = None
user_auth_tuple = BasicAuthentication().authenticate(request)
if user_auth_tuple is not None:
user, _ = user_auth_tuple