quick question. I run the following code with a try except
statement (as it is possible that there is no entry in the database). And for some entries I run into the except block although there is an entry in the database for sure! When using objects.filter()
instead of objects.get()
I do not have this problem - it never goes to the except block for the same entries in the database!
key = "anystringasprimarykey"
username = "anyusername"
try:
entry = MyDatabase.objects.get(ort=key, user=username)
except:
print("oh, exception!")
Can anybody give me a tip on what I am doing wrong?
except MyDatabase.DoesNotExist
to capture more exact type of exception. It is the generalexcept
that hides the exception you are confused of. – Carnelian