wyc's domain


Adding Basic Auth to Django

Posted on May 29, 2017
Tags: python, django

I was writing a Django application for a project and needed to protect it from the general public. An amazingly simple library called wsgi_basic_auth made this easy.

Added to my requirements.txt:

wsgi_basic_auth==1.1.*

Appended to my app/wsgi.py:

# Tack on HTTP Basic Auth
# Configured with env variables:
#   WSGI_AUTH_CREDENTIALS=user:password
#   WSGI_AUTH_EXCLUDE_PATHS=/not/protected
#   WSGI_AUTH_PATHS=/protected
from wsgi_basic_auth import BasicAuth
application = BasicAuth(application)

Some pre-deploy checks: