fastapi框架
一、安装fastapi
pip install uvicorn pip install fastapi
二、fastapi框架搭建
导入模块->创建fastapp框架对象->@app路由装饰器收发数据->运行服务器
from fastapi import FastAPI
from fastapi import Response
import uvicorn
app=FastAPI()
@app.get("/render.html")
def func01():
with open("./html/html/render.html", "rb") as f:
file_data = f.read()
return Response(content=file_data,media_type="text/html")
@app.get("/gdp.html")
def func01():
with open("./html/html/gdp.html", "rb") as f:
file_data = f.read()
return Response(content=file_data,media_type="text/html")
uvicorn.run(app,host="127.0.0.1",port=8080)