[Django]-Django: Check if a user is logged in before allowing them to register?

2👍

Just return what the parent FormView would have returned

def get(self, request):
    if request.user.is_authenticated():
        # If a user is logged in, redirect them to a page informing them of such
        return render(request, 'users/already_logged_in.html')
    else:
        return super(RegisterView, self).get(request)

You’ll need to set form_class on your view, rather than in your post Method, look at the django docs for how to use FormView https://docs.djangoproject.com/en/1.7/ref/class-based-views/generic-editing/#formview

Leave a comment