0

虽然使用无效字段订购 django 查询集不会引发任何异常,但这是我的代码

try:
    object_list = Foo.objects.all().order_by('zz')#invalid
except:
    object_list = Foo.objects.all().order_by('-id')#valid

但它不会阻止我如何解决请帮忙?

4

1 回答 1

0

I tryed your exemple. An invalid order_by raise:

FieldError: Cannot resolve keyword 'zz' into field. Choices are: [...]

How do you see it doesn't go in your except block? if you are looking in database logs, nothing will be loaded until you evaluate your queryset.

于 2012-10-09T07:11:41.477 回答