Created
May 14, 2016 13:20
-
-
Save shangxiao/db2924247238862f83f34a083730991a to your computer and use it in GitHub Desktop.
Django view decorator for returning 404 if not authenticated
This file contains 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 functools import update_wrapper | |
from django.http import Http404 | |
class authenticated_or_404(object): | |
def __init__(self, func): | |
self.func = func | |
update_wrapper(self, func) | |
def __call__(self, request, *args, **kwargs): | |
if not request.user.is_authenticated(): | |
raise Http404 | |
return self.func(request, *args, **kwargs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment