How would I insert “if request.user.is_authenticated” into the form wizard class below like shown in the example below? The idea is this view is my homepage and I would like to redirect to a different page if the user is already logged in.
Currently it is giving me “name ‘request’ is not defined” as an error message. I tried class BusinessWizard(request, SessionWizardView), but unfortunately it did not work. Maybe it is a simple oversight on my part. Thank you for your help!
views.py
class BusinessWizard(SessionWizardView):
if request.user.is_authenticated:
HttpResponseRedirect('some url')
else:
#some code and functions etc
The easiest way is to add the
login_requireduser_passes_test decorator in the urlconf:Reference:
https://docs.djangoproject.com/en/dev/topics/class-based-views/#decorating-in-urlconf
https://docs.djangoproject.com/en/dev/topics/auth/default/#django.contrib.auth.decorators.user_passes_test
If you want to define your own decorator you can use the following snippet: