我想检查一个对象是否在我的views.py中返回一个值,这是我的代码......
city = City.objects.get(name=form.cleaned_data['autocompleteCity'])
所以,我在想这样的事情......
city = City.objects.get(name=form.cleaned_data['autocompleteCity'])
if city:
#we have results do something with city object
else:
#no results display error and stop processing form.
解决此问题的最佳方法是什么。