【发布时间】:2019-07-07 11:16:06
【问题描述】:
我正在尝试使用 Django ORM 来查询 API 而不是数据库。 我找到了 Django Rest Models 库,它与库 dynamic-rest 结合使用。
我的模型叫做 Client,当我运行时:
Client.objects.filter(id=62)
我收到以下错误:
ImproperlyConfigured: the response does not contains the result for client.
maybe the resource name does not match the one on the api. please check if
Client.APIMeta.resource_name_plural is ok had [u'last_name', u'first_name',
u'agent',...] in result
谁能帮助我了解如何解决此错误?
附加信息
这是我在客户端上的模型
class Client(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
agent = models.ForeignKey(Agent, db_column='agent')
.....
class APIMeta:
resource_path = 'clients'
resource_name = 'client'
resource_name_plural = 'clients'
pass
这是我在 API 上的代码
class ClientSerializer(DynamicModelSerializer):
agent = DynamicRelationField('AgentSerializer')
class Meta:
fields = '__all__'
model = Client
name = 'client'
class AgentSerializer(DynamicModelSerializer):
client = DynamicRelationField('ClientSerializer', many=True)
class Meta:
fields = '__all__'
model = Agent
更新
调试后发现返回的数据没有模型名作为key。如何返回所需格式的数据?
【问题讨论】:
-
这是整个错误信息吗?它还应该打印响应中存在的键。打印出来了吗?
-
请发布完整的回溯。
标签: python django python-2.7 django-models dynamic-rest