Skip to content

Instantly share code, notes, and snippets.

@bancek
Created July 7, 2015 15:11
Show Gist options
  • Save bancek/665529b778fd243fab5f to your computer and use it in GitHub Desktop.
Save bancek/665529b778fd243fab5f to your computer and use it in GitHub Desktop.
Django login required middleware
from django.http import HttpResponseRedirect
from django.conf import settings
class LoginRequiredMiddleware:
def process_request(self, request):
if not request.user.is_authenticated():
path = request.path_info
if not path.startswith('/accounts/'):
return HttpResponseRedirect(settings.LOGIN_URL)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment