我有下面的代码和错误堆栈跟踪。我正在尝试访问localhost:8000/fundamentals/,但收到错误消息'list' object has no attribute 'values'错误web_1 | Traceback (most recent call last):web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/exception.py", line 47, in innerweb_1 | response = get_response(request)web_1 | File "/usr/local/lib/python3.7/site-packages/django/core/handlers/base.py", line 202, in _get_responseweb_1 | response = response.render()web_1 | File "/usr/local/lib/python3.7/site-packages/django/template/response.py", line 105, in renderweb_1 | self.content = self.rendered_contentweb_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/response.py", line 70, in rendered_contentweb_1 | ret = renderer.render(self.data, accepted_media_type, context)web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/renderers.py", line 724, in renderweb_1 | context = self.get_context(data, accepted_media_type, renderer_context)web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/renderers.py", line 655, in get_contextweb_1 | raw_data_post_form = self.get_raw_data_form(data, view, 'POST', request)web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/renderers.py", line 563, in get_raw_data_formweb_1 | data = serializer.data.copy()web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 562, in dataweb_1 | ret = super().dataweb_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 264, in dataweb_1 | self._data = self.get_initial()web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 412, in get_initialweb_1 | for field in self.fields.values()web_1 | File "/usr/local/lib/python3.7/site-packages/rest_framework/serializers.py", line 413, in <listcomp>
1 回答
动漫人物
TA贡献1815条经验 获得超10个赞
这里的问题是与BalanceSheetSerializer
. 必须fields
在类中定义,Meta
而不是将其定义为类变量。
class BalanceSheetSerializer(serializers.ModelSerializer): class Meta: fields = [your_fields]
添加回答
举报
0/150
提交
取消