【发布时间】:2017-08-17 18:36:17
【问题描述】:
当我尝试向我的模型发出 GET(使用 TastyPie)时,我收到以下回溯错误:
File "/Library/Python/2.7/site-packages/tastypie/resources.py", line
2141, in get_object_list
return self._meta.queryset._clone()
AttributeError: 'NoneType' object has no attribute '_clone'
下面是我的resources.py 文件,用于相关模型。
from tastypie.resources import ModelResource
from swtr.models import Com
class ComResource(ModelResource):
class Meta:
query_set = Com.objects.all()
resource_name = 'com'
object_class = none
考虑到Com.objects.all() 返回至少一条我在python shell 中创建并保存的记录,我感到特别困惑。所以我不确定为什么查询集被返回为NoneType。
【问题讨论】:
-
包括完整的回溯和导致此错误的视图
-
您确定在您的
ComResource的元类中是query_set而不是queryset? -
@wencakisa 哇——你是对的——它是查询集!我不知道在翻阅文档时我是怎么错过的……非常感谢您为我发现了这一点。