Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Basic auth utilities for Django.

Project Description

Basic auth utilities for Django.


Tested under…

  • Python
    • 2.7
    • 3.6
  • Django
    • 1.8
    • 1.10
    • 1.11


pip install django-basicauth


from basicauth.decorators import basic_auth_required

def myview(request):

or by a middleware.


Basic Auth for specific requestno only

To apply basic auth for specific requests, Use target_test argument.

In the below code, anonymous users will be required Basic Auth Authenticated users can pass it without Basic … header.

from basicauth.decorators import basic_auth_required

    target_test=lambda request: not request.user.is_authenticated
def myview(request):

target_test accepts typing.Callable[[HttpRequest], bool], and if the callable returns True, Basic Auth will be required.

Applying decorator to CBVs

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

from django.utils.decorators import method_decorator
from basicauth.decorators import basic_auth_required

@method_decorator(basic_auth_required, name='dispatch')
class YourView(TemplateView):
    template_name = "my-template.html"


  • BASICAUTH_USERS (required): Dictionary including keys as username and values as passwords.
  • BASICAUTH_REALM: realm string, default is “Secure resource”.
  • BASICAUTH_DISABLE: Disable all of barriers by this library.


0.4.2 (2017-11-27)

  • Fixed to avoid timing attacks
    • Lots of thanks for Hugo Castilho

0.4.1 (2017-10-20)

  • Added target_test argument for the decorator.

0.4 (2017-09-30)

  • Supported Python 2.7
  • Dropped Django1.9
  • Supported Django 1.10+ style middleware

0.3 (2017-08-28)

  • Added BASICAUTH_DISABLE setting
  • Changed API of basicauthutils.validate_request
    • Fixed to return True/False
    • Adding REMOTE_USER by this function

0.2.1 (2017-08-28)

  • Officially supported Django 1.11, 1.10, 1.9

0.2 (2016-03-31)

0.1 (2015-04-20)

  • Initial

Release History

This version
History Node


History Node


History Node


History Node


History Node


History Node


History Node


Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(6.7 kB) Copy SHA256 Hash SHA256
Wheel 3.6 Nov 27, 2017
(5.0 kB) Copy SHA256 Hash SHA256
Source None Nov 27, 2017

Supported By

Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Google Google Cloud Servers