Python Flask-RESTful: 'AttributeError: 'function' object has no attribute 'items'' 解决方法
The error 'AttributeError: 'function' object has no attribute 'items'' occurs because the fields.Nested() function should receive a dictionary of field attributes, but in your code, you are passing a lambda function instead.
To fix this issue, you need to define the person_task_fields dictionary before using it inside the fields.Nested() function. Here's the corrected code:
from flask_restful import fields
person_task_fields = {
'children': fields.List(fields.Nested(lambda: person_task_fields)),
}
By defining the person_task_fields dictionary before using it, the lambda function will have access to the dictionary's attributes, and the error will be resolved.
原文地址: https://www.cveoy.top/t/topic/pe3C 著作权归作者所有。请勿转载和采集!