我一直收到以下错误:
Traceback (most recent call last):
File "/srv/www/poka/app/env/main/lib/python2.7/site-packages/tastypie/resources.py", line 217, in wrapper
response = callback(request, *args, **kwargs)
File "/srv/www/poka/app/env/main/lib/python2.7/site-packages/tastypie/resources.py", line 459, in dispatch_list
return self.dispatch('list', request, **kwargs)
File "/srv/www/poka/app/env/main/lib/python2.7/site-packages/tastypie/resources.py", line 491, in dispatch
response = method(request, **kwargs)
File "/srv/www/poka/app/env/main/lib/python2.7/site-packages/tastypie/resources.py", line 1299, in get_list
objects = self.obj_get_list(bundle=base_bundle, **self.remove_api_resource_names(kwargs))
File "/srv/www/poka/app/env/main/lib/python2.7/site-packages/tastypie/resources.py", line 2113, in obj_get_list
return self.authorized_read_list(objects, bundle)
File "/srv/www/poka/app/env/main/lib/python2.7/site-packages/tastypie/resources.py", line 610, in authorized_read_list
auth_result = self._meta.authorization.read_list(object_list, bundle)
File "/srv/www/poka/app/env/main/lib/python2.7/site-packages/tastypie/authorization.py", line 151, in read_list
klass = self.base_checks(bundle.request, object_list.model)
AttributeError: 'list' object has no attribute 'model'
当我调用以下模型时会发生这种情况:
class NewsResource(ModelResource):
class Meta:
queryset = News.objects.select_related('picture').all()
allowed_methods = ['get','patch']
include_resource_uri = False
include_absolute_url = False
authentication = ApiKeyAuthentication()
authorization = DjangoAuthorization()
有什么想法吗?
答案 0 :(得分:1)
正如Hai vu所说,你的对象没有model
属性。
为帮助您了解问题,可以使用PDB对其进行调试。 设置起来非常简单。 在负责问题的行之前,请在您的代码中写下:
import pdb; pdb.set_trace()
它将冻结您的服务器作为代码中的这一点。 然后在shell中,随意测试如下内容:
list.model # will throw the same error
或
list.__dict__ # will show all the possible attributes that you can use with the list object
答案 1 :(得分:0)
以下是演示错误的示例:
>>> object_list = [1, 2, 3]
>>> object_list.model
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'list' object has no attribute 'model'
我怀疑你的案例中的object_list
是一个列表,因此没有属性model
。请检查您的代码。