Django : using HTTP authentication for your views

This is a small tutorial on how to use HTTP authentication for your site. Firstly you need to copy this file to httpauth.py and place it at /httpauth.py import base64 from django.contrib.auth.models import User from django.http import HttpResponse from django.contrib.auth import authenticate, login ############################################################################# def view_or_basicauth(view, request, test_func, realm = “”, *args, **kwargs): """ This is a helper function used by both ‘’logged_in_or_basicauth’’ and ‘‘has_perm_or_basicauth’’ that does the nitty of determining if they are already logged in or if they have provided proper http-authorization and returning the view if all goes well, otherwise responding with a 401....

November 15, 2008 · 3 min · 526 words · Me