how to catch the MultipleObjectsReturned error in django

Use a filter:

Location.objects.filter(name="Paul").first()

Or import the exception:

from django.core.exceptions import MultipleObjectsReturned
...
try:
    Location.objects.get(name="Paul")
except MultipleObjectsReturned:
    Location.objects.filter(name="Paul").first()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)