《zdppy_aocrud官方教程》 05 自动生成更新接口

05 自动生成更新接口

《zdppy_aocrud官方教程》 05 自动生成更新接口

自动生成更新方法

服务端

import aocrud
import env
import orm
from api import Api, resp

env.load("../.env")

db, BaseModel = orm.get_mysql_pool_base_model_by_env()


class User(BaseModel):
    name = orm.CharField()
    age = orm.IntegerField()


path, method = aocrud.method.update(User)

app = Api(routes=[
    resp.put(path, method)
])

if __name__ == "__main__":
    import uvicorn

    uvicorn.run("server:app", port=8000)

客户端

import req

data = {
    "name": "张三3",
    "age": 23,
}
r = req.put("http://127.0.0.1:8000/user/3")
print(r.json())

r = req.put("http://127.0.0.1:8000/user/3", json=data)
print(r.json())

自动生成更新路由

服务端

import aocrud
import env
import orm
from api import Api

env.load("../.env")

db, BaseModel = orm.get_mysql_pool_base_model_by_env()


class User(BaseModel):
    name = orm.CharField()
    age = orm.IntegerField()


app = Api(routes=[
    aocrud.route.update_route(User)
])

if __name__ == "__main__":
    import uvicorn

    uvicorn.run("server:app", port=8000)

客户端

import req

data = {
    "name": "张三3",
    "age": 23,
}
r = req.put("http://127.0.0.1:8000/user/3")
print(r.json())

r = req.put("http://127.0.0.1:8000/user/3", json=data)
print(r.json())

你可能感兴趣的:(python)