Created
July 7, 2015 15:11
-
-
Save bancek/665529b778fd243fab5f to your computer and use it in GitHub Desktop.
Django login required middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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