最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Python(flask) PUT TypeError: Todo.put() got multiple values for argument 'todo_id' - Stack Overflow

programmeradmin1浏览0评论

I am creating a todo list app using React and Python. But the update todo function is not working properly and gave me TypeError: Todo.put() got multiple values for argument 'todo_id'.

@blp.arguments(TodoUpdateSchema)
@blp.response(200, TodoSchema)
def put(self, todo_id, todo_data):

    todo = TodoModel.query.get(todo_id)
    if todo:
        todo.todo = todo_data["todo"]
        todo.checked = todo_data["checked"]
    else:
        return {"message": "todo not found"}

    db.session.add(todo)
    db.sessionmit()

    return todo 

This is my Python handling method and from React I am sending:

export const updateTodo = async (id: number, editTodo: EditTodo) => {
    const response = await axios.put(`${TODO_API_URL}/${id}`, editTodo);
    return response.data;
};

It gave me a 422 HTTP status code. I have no idea how to fix it. Can anyone help me please?

class TodoSchema(Schema):
    id = fields.Int(dump_only=True)
    date = fields.Date(required=True)
    todo = fields.Str(required=True)
    checked = fields.Bool(required=False)

class TodoUpdateSchema(Schema):
    class Meta:
        unknown = EXCLUDE
    todo = fields.Str(required=True)
    checked = fields.Bool(required=True)

I kept changing the schema and parameter to send, but nothing is working.

发布评论

评论列表(0)

  1. 暂无评论