I'm trying to work out an exception problem I've been having with django: I have a view with the following call with an url http://someurl.com/?items=1,2,3. I want to deal with cases where ?items= or ?items=somthing_bs. When I always get the error: local variable 'apps' referenced before assignment. Shouldn't it catch all the exceptions and errors that come it's way in the try clause? My code:
def my_view(request):
if request.GET.get('mashpoint'):
try:
item_ids = request.GET.get('mashpoint')
item_ids = item_ids.split(',')
apps = mpApp.objects.filter(mpitem__pk__in=item_ids).distinct()
return render_to_response(template_name,context_instance=RequestContext(request,{'apps':apps,'item_ids':','.join(item_ids)}))
except:
return render_to_response(template_name,context_instance=RequestContext(request,{}))
return render_to_response(template_name,context_instance=RequestContext(request,{}))