Hey, I'm getting into django and this is getting me a headache. I'm trying to get a simple GET variable. URL is site.com/search/?q=search-term
My view is:
def search(request):
if request.method == 'GET' and 'q' in request.GET:
q = request.GET.get('q', None)
if q is not None:
results = Task.objects.filter(
Q(title__contains=q)
|
Q(description__contains=q),
)
...return...
else:
...
else:
...
Search queries like: mysite.com/search/? (without q) gets through the first if correctly.
The problem is in queries like mysite.com/search/?q=. They don't get caught by if q is not None:
So, the short answer would be How can I check q == ''? (I've already tried '', None, etc, to no avail.)