Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Django view decorator for returning 404 if not authenticated
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