【问题标题】:Issue updating an order with an authorized user(FastAPI)使用授权用户更新订单问题(FastAPI)
【发布时间】:2021-11-15 05:52:10
【问题描述】:

我不知道我在这里做错了什么。我想用订单 ID 更新订单,但我得到了TypeError: dict() takes exactly 1 positional argument (0 given)。但是,当我更新用户时,它运行良好。

@order_router.put('/update/{order_id}', response_model=Order_Pydantic)
async def update_by_order_id(order_id: str, order=OrderModel, Authorize: AuthJWT = Depends()):
    
    try:
        Authorize.jwt_required()
    except Exception as e:
        raise HTTPException(
            status_code=status.HTTP_401_UNAUTHORISED, detail='Invalid Token'
        )
    await Order.filter(id=order_id).update(**order.dict(exclude_unset=True))
    return Order_Pydantic.from_queryset_single(Order.get(id=order_id))

【问题讨论】:

    标签: fastapi tortoise-orm


    【解决方案1】:

    我已经看到错误的来源。我使用 order=OrderModel 而不是 order: OrderModel

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2019-11-07
    • 2019-02-08
    • 2019-06-18
    • 2011-03-26
    • 2020-03-31
    • 1970-01-01
    • 2019-09-27
    • 1970-01-01
    • 2011-02-06
    相关资源
    最近更新 更多