Saturday, 7 September 2013

Python django how to properly test if a queryset returned a result

Python django how to properly test if a queryset returned a result

pI haven't had a very thorough training in python and sometimes don't know
the emcorrect/em way of doing things. One of these things is testing if my
resultQuery returned a result or not. I find myself doing this a lot:/p
precode try: user = User.objects.get(email=email) except DoesNotExist:
user = User() /code/pre pI don't know about python but try catches in
other languages are supposed to be for exceptions and not for normal
program flow. How would you do this with an if else? I guess I want
something similar to:/p precodeif request.GET.get('email','') is not None:
email = request.GET['email']) /code/pre

No comments:

Post a Comment