Форум сайта python.su
есть код
>>> dt_value = measuring_datetime.objects.latest('dt_value')
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Python25\Lib\site-packages\django\db\models\manager.py", line 93, in
latest
return self.get_query_set().latest(*args, **kwargs)
File "C:\Python25\lib\site-packages\django\db\models\query.py", line 306, in l
atest
return self._clone(_limit=1, _order_by=('-'+latest_by,)).get()
File "C:\Python25\lib\site-packages\django\db\models\query.py", line 263, in g
et
raise self.model.DoesNotExist, "%s matching query does not exist." % self.mo
del._meta.object_name
DoesNotExist: measuring_datetime matching query does not exist.
try :
dt_value = measuring_datetime.objects.latest('dt_value')
exception DoesNotExist:
print "DoesNotExist"
[code]
получаю
[code]
NameError at /
global name 'DoesNotExist' is not defined
Request Method: GET
Request URL: http://127.0.0.1:8000/
Exception Type: NameError
Exception Value: global name 'DoesNotExist' is not defined[/code]
как сделать import для данного exception
Офлайн
Django documentationт.е.
get() raises a DoesNotExist exception if an object wasn’t found for the given parameters. The DoesNotExist exception is an attribute of the model class.
try:
page = Page.objects.get(url='/page_url/')
except Page.DoesNotExist:
print "What's a funny url for page? :)"
Офлайн
отработало
try: measuring_datetime.DoesNotExist
Офлайн