MultipleObjectsReturned get() returned more than one Model -- it returned 2!

Raised by:

django/db/models/ (line 338)

Traceback (most recent call last):
  File "python2.7/site-packages/django/core/handlers/", line 132, in get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "python2.7/site-packages/django/views/generic/", line 71, in view
    return self.dispatch(request, *args, **kwargs)
  File "python2.7/site-packages/django/views/generic/", line 89, in dispatch
    return handler(request, *args, **kwargs)
  File "python2.7/site-packages/django/views/generic/", line 115, in get
    self.object = self.get_object()
  File "python2.7/site-packages/django/views/generic/", line 53, in get_object
    obj = queryset.get()
  File "python2.7/site-packages/django/db/models/", line 338, in get
    (self.model._meta.object_name, num)
MultipleObjectsReturned: get() returned more than one ErrorPost -- it returned 2!

How to reproduce

Create a DetailView that gets object from a slug and don't guarantee that slug is unique on object's model.

How to fix

Try the following:

  • guarantee the slug is unique.
  • guarantee your get_object of DetailView is using at least one unique attribute to get the object from model.