Python 从DoesNotExist异常实例获取查找参数

Python 从DoesNotExist异常实例获取查找参数,python,django,Python,Django,有一个部分显示某些代码,其中引发了DoesNotExist异常: # Request an ID that doesn't exist, this will raise an exception. >>> Poll.objects.get(id=2) Traceback (most recent call last): ... DoesNotExist: Poll matching query does not exist. Lookup parameters were

有一个部分显示某些代码,其中引发了
DoesNotExist
异常:

# Request an ID that doesn't exist, this will raise an exception.
>>> Poll.objects.get(id=2)
Traceback (most recent call last):
    ...
DoesNotExist: Poll matching query does not exist. Lookup parameters were {'id': 2}
异常实例上的消息显示用于查找的参数。但我没有看到这些参数:

>>> django.get_version()
'1.5.6'
>>> Client.objects.get(pk=2)
Traceback (most recent call last):
    ...
DoesNotExist: Client matching query does not exist.

实际上,这些信息对于我的项目调试日志非常有用。为什么我们不看看它,如果可能的话,如何重新打开它?

本教程是为Django 1.5编写的。当时的例外情况更为详细:

但是,在最新版本中,异常消息已更改,现在仅包含:

仅供参考,实际用户试图解决此问题

raise self.model.DoesNotExist(
          "%s matching query does not exist. "
          "Lookup parameters were %s" %
          (self.model._meta.object_name, kwargs))
raise self.model.DoesNotExist(
          "%s matching query does not exist." %
          self.model._meta.object_name)