Skip to content

Instantly share code, notes, and snippets.

@pstch
Created November 9, 2012 09:59
Show Gist options
  • Save pstch/4044948 to your computer and use it in GitHub Desktop.
Save pstch/4044948 to your computer and use it in GitHub Desktop.
Django View that requires login when using site-wide login forms
class ProtectedTemplateView(TemplateView):
def dispatch(self, request, *args, **kwargs):
if not request.user.is_authenticated():
print 'Potatoes !'
return render(request, 'syncoor/auth/login_required.html', {'next' : request.get_full_path(), 'login_form_present' : True})
return super(ProtectedTemplateView, self).dispatch(request,*args, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment