Hi guys,
I'm working on the tutorial in www.djangobook.com and I reached the
point where I'm making a search form, here is what my view methods
look like:
def search_form(request):
return render_to_response('search_form.html')
def search(request):
error = False
if 'q' in request.GET and request.GET['q']:
q = request.GET['q']
if not q:
error = True
else:
books = Book.objects.filter(title__icontains=q)
return render_to_response('search_results.html',
{'books':books, 'query':q})
return render_to_response('search_form.html', {'error':error})
the search_form template looks like:
<html>
<body>
<form action="/search" method="get">
{% if error %}
<p style="color:red;"> Please submit a search term </p>
{% endif %}
Enter the name of the book you're looking for:
<br />
<br />
<input type="text" name="q">
<input type="submit" value="Search">
</form>
</body>
</html>
now, i am supposed to get the error message "Please submit a search
term" if i submit an empty request. but that is not happening, instead
i'm getting the ordinary search_form without the error message.
anybody can give me a hint why?
thanks in advance,
cheers,
Lina
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---