Hi Brad,
1. Why would app not be not be set if it is in the try statement?
Because the except parameter has the app variable in it (which it shouldn't). The correct except definition should be: "except Application.DoesNotExist". You are not looking for if the app variable doesn't exist but rather an object of type Application in the database.
2. See above :)
Med vänliga hälsningar,
Andréas Kühne
Software Development Manager
Suitopia Scandinavia AB
2014-09-06 18:38 GMT+02:00 Brad Rice <bradrice1@gmail.com>:
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 completeexcept app.DoesNotExist:app = Nonereturn 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.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/261bf20e-c41e-4898-9c8a-8d3315388de6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CALXYUbkB33MMtQxoVZDCzbyRqxHjr5Agb4iw25aKmkWOSyeY6g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment