【问题标题】:How to convert reqParser in flask to faspapi in python?如何将烧瓶中的 reqParse 转换为 python 中的 fastapi?
【发布时间】:2021-01-27 09:20:27
【问题描述】:

我正在 python 中从烧瓶迁移到 fastapi,但在转换时遇到问题 这段代码和平成 fastapi

from flask_restx import Resource, Api, fields, reqparse
//some code to generate uuid and add it to the request after login
reqParser = reqparse.RequestParser()
reqParser.add_argument('sid', help='session id', required=True)

他们有什么方法可以将其转换为 fastapi? 我在他们的文档中进行了搜索,但没有找到。

【问题讨论】:

    标签: python fastapi


    【解决方案1】:

    您可以查看包含有关您传入请求的所有信息的请求对象。

    from fastapi import Request
    
    
    @app.get("/dummy")
    async def dummy(request: Request):
         print(request.__dict__)
    

    【讨论】:

    • 感谢@Yagiz Degirmenci 的帮助,但我想在请求中添加 uuid,例如 about 但在 fastapi 中,但我不明白您的回答
    • 是否要将 UUID 添加到响应标头中?
    • 是的,这就是我想要做的
    猜你喜欢
    • 2015-04-01
    • 1970-01-01
    • 2021-05-01
    • 1970-01-01
    • 1970-01-01
    • 2022-07-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多