On Mon, Mar 23, 2009 at 8:53 PM, AKK <andrewkenyon...@gmail.com> wrote:

>
> Hi,
>
> I'm working through chapter 7 of the djangobook online. and i've got
> the following:
>
> def search(request):
>    if 'criteria' in request.GET:
>        message = 'You searched for: %r' % request.GET['criteria']
>    else:
>        message = 'You submitted an empty form.'
>    return HttpResponse(message)
>
> however, if i leave it blank rather than it saying "You submitted an
> empty form" it says:
>
> You searched for: u''.
>
> Can someone tell me how to fix this or mention why it occurs?
>
> Thanks,
>
> Andrew
> >
>
It occurs because the URL you went to was /search/?criteria=

Which the webserver and Django understand to mean that criteria is a key
whos value is '', fix this change the first conditional to be:
if request.GET.get('conditional')

Which means "if conditional is in GET return it, else return None" both of
which will evaluate to False in a boolean context.

Alex

-- 
"I disapprove of what you say, but I will defend to the death your right to
say it." --Voltaire
"The people's good is the highest law."--Cicero

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@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
-~----------~----~----~----~------~----~------~--~---

Reply via email to