Files
1/main.py
T
2026-09-14 10:23:36 +08:00

42 lines
1.6 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#项目初始化入口
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
# 周学灵、熊浩钦、圣国伟、刘盼、彭少、赵康宁的路由
from api import wl_student_api,wl_class_api,wl_score_api,wl_teacher_api,statistics,wl_emp_api,wl_advisor_api
from database import Base, engine
# wl_emp_model 必须显式导入:否则 wl_emp 表只能靠 statistics 的传递导入进 metadata,
# 一旦统计路由被拿掉,create_all 会漏建 wl_emp,Student.emp 关系随即报错
from model import wl_student_model,wl_class_model,wl_advisor_model,wl_score_model,wl_teacher_model,wl_emp_model
Base.metadata.drop_all(engine)
Base.metadata.create_all(bind=engine)
app = FastAPI(title="沃林学生管理系统")
# 前端页面单独起一个静态服务器(在 static 目录里执行 python -m http.server 8080),
# 和后端不同源,所以由后端放行跨域请求。这里不挂载静态文件。
# 注意:allow_origins=["*"] 不能和 allow_credentials=True 同时用,浏览器会直接拒绝;
# 本项目接口没有登录态、不需要带 cookie,所以可以放心用 "*"。
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
app.include_router(wl_student_api.router)
app.include_router(wl_class_api.router)
app.include_router(wl_score_api.router)
app.include_router(wl_teacher_api.router)
app.include_router(statistics.router)
app.include_router(wl_emp_api.router)
app.include_router(wl_advisor_api.router)
if __name__ == "__main__":
import uvicorn
uvicorn.run("main:app", host="0.0.0.0", port=8001,reload=True)