《zdppy_aocrud官方教程》 09 自动生成查询所有接口
import aocrud
import env
import orm
from api import resp, Api
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.get_all(User, "user")
app = Api(routes=[
resp.get(path, method),
resp.get("/users", method),
])
if __name__ == "__main__":
import uvicorn
uvicorn.run("server:app", port=8000)
import req
r = req.get("http://127.0.0.1:8000/user")
print(r.json())
r = req.get("http://127.0.0.1:8000/users")
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.get_all_route(User, "user"),
aocrud.route.get_all_route(User, "users"),
])
if __name__ == "__main__":
import uvicorn
uvicorn.run("server:app", port=8000)
import req
r = req.get("http://127.0.0.1:8000/user")
print(r.json())
r = req.get("http://127.0.0.1:8000/users")
print(r.json())