Skip to content

Instantly share code, notes, and snippets.

View theshane's full-sized avatar

Shane Burgess theshane

View GitHub Profile
@theshane
theshane / LoginRequiredMiddleware.py
Last active February 22, 2017 01:41 — forked from r0yfire/LoginRequiredMiddleware.py
Django Login Required Middleware (Updated for 1.10)
from re import compile
from django.conf import settings
from django.http import HttpResponseRedirect
from django.utils.http import is_safe_url
from django.utils.deprecation import MiddlewareMixin
EXEMPT_URLS = [compile(settings.LOGIN_URL.lstrip('/'))]
if hasattr(settings, 'LOGIN_EXEMPT_URLS'):
EXEMPT_URLS += [compile(expr) for expr in settings.LOGIN_EXEMPT_URLS]