如何解决python使用烧瓶方法视图在__init__方法中获取实体
使用烧瓶MethodView
app.add_url_rule('/fruit/<fruit>',method=['POST'],view_func=Fruit.as_view('fruit_types'))
示例:
curl -X POST 'http://localhost:5000/apples'
我有以下课程:
class Fruit(MethodView):
def __init__(self):
# I want to process fruit (apples) here
def post(self,fruit):
# fruit variable = apples here
我可以邮寄苹果,但也希望通过 init
我尝试过:
def __init__(self,fruit):
但是后来我得到TypeError init ()缺少1个必需的位置参数:“ fruit”
这可能吗?我在做什么错了?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。