from fastapi import FastAPI,APIRouter from students.api.students_api import s_api from students.databases import * from students.model import students_model from contextlib import asynccontextmanager # 合并接口 @asynccontextmanager async def S_Router(Students_API: APIRouter): Base.metadata.create_all(engine1) yield engine1.dispose() Students_API = APIRouter(lifespan=S_Router) Students_API.include_router(s_api) # 自测接口 @asynccontextmanager async def S_Fastapi(app: FastAPI): Base.metadata.create_all(engine1) yield engine1.dispose() app = FastAPI(title="学生管理系统",lifespan=S_Fastapi) # 这里必须把上面写的加上 app.include_router(s_api,tags=["students"]) if __name__ == "__main__": def main(): print("Hello from student-manage-system!") import uvicorn uvicorn.run("main:app", host="0.0.0.0", port=51000) """students api IPv4 地址 . . . . . . . . . . . . : 192.168.6.40 默认网关. . . . . . . . . . . . . : 192.168.6.1 """