I'm trying to write a try: except: to check for three things. First I want to check if an application has already been filled out, thus, check for existence. Second if it has been filled out a flag that is is complete is set to true. Then the else would be neither of those things, they need to create a new app.
This is what I have started with:
class Main(TemplateView):
# app_started = Application.objects.get(created_by=request.user)
@method_decorator(login_required(login_url='/accounts/login/'))
def dispatch(self, *args, **kwargs):
try:
app = Application.objects.get(created_by=self.request.user)
# if it is true check for if the app is set to complete
except app.DoesNotExist:
app = None
return HttpResponseRedirect(reverse('requestform:registrant_create'))
else:
return HttpResponseRedirect(reverse('requestform:registrant_update'))
I keep getting this error:
local variable 'app' referenced before assignment
Why would app not be not be set if it is in the try statement?
How would I check if it does exist, to then check if the flag is true?
I'm sort of a Django newbie and this portion of the code I am writing is really mystifying me.