Hi, You are catching a KeyError while it throws and IndexError ;)
Regards, Xavier. Le 20 sept. 2010 à 17:04, grimmus a écrit : > Hi, > > On the homepage of my website i list 1 random ad in the right column. > In my view i retrieve it like so: > > side_ad = SideAd.objects.filter(active=1).order_by("?")[0] > > If all ad's are inactive no object's will be returned thus creating an > IndexError : list out of range > > I tried to wrap the above in a try/except block but it's still the > same error: > > try: > side_ad = SideAd.objects.filter(active=1).order_by("?")[0] > except (KeyError,SideAd.DoesNotExist): > side_ad = None > > I still pass side_ad back in the context. > > Could someone tell me what I'm doing wrong ? > > Thanks. > > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To post to this group, send email to django-us...@googlegroups.com. > To unsubscribe from this group, send email to > django-users+unsubscr...@googlegroups.com. > For more options, visit this group at > http://groups.google.com/group/django-users?hl=en. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.