Tastypie: getting "AttributeError: 'NoneType' object has no attribute '_clone'" Error

Tastypie: getting "AttributeError: 'NoneType' object has no attribute '_clone'" Error

当我尝试向我的模型发出 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() returns 我在 python shell 中创建并保存了至少一条记录。所以我不确定为什么查询集作为 NoneType.

返回

ComResourceMeta class.

中的某些字段拼写错误

尝试将 query_set 重命名为 queryset 并将 object_class 的值设为 None,而不是 none:

from tastypie.resources import ModelResource
from swtr.models import Com


class ComResource(ModelResource):
    class Meta:
        queryset = Com.objects.all()
        # __^
        resource_name = 'com'
        object_class = None
        # _____________^