Django request.GET
since your form has a field called 'q', leaving it blank still sends an empty string.
try
if 'q' in request.GET and request.GET['q'] != "" :
message
else
error message
q = request.GET.get("q", None)
if q:
message = 'q= %s' % q
else:
message = 'Empty'
Calling /search/
should result in "you submitted nothing", but calling /search/?q=
on the other hand should result in "you submitted u''"
Browsers have to add the q=
even when it's empty, because they have to include all fields which are part of the form. Only if you do some DOM manipulation in Javascript (or a custom javascript submit action), you might get such a behavior, but only if the user has javascript enabled. So you should probably simply test for non-empty strings, e.g:
if request.GET.get('q'):
message = 'You submitted: %r' % request.GET['q']
else:
message = 'You submitted nothing!'