from django.http import HttpResponse from django.conf import settings class BasicAuthMiddleware(object): def unauthed(self): response = HttpResponse("""<html><title>Auth required</title><body> <h1>Authorization Required</h1></body></html>""", mimetype="text/html") response['WWW-Authenticate'] = 'Basic realm="Development"' response.status_code = 401 return response def process_request(self,request)