pip install fastapi
from fastapi import FastAPI
from fastapi import Response
import uvicorn
#创建fastapp框架对象
app=FastAPI()
#@app路由装饰器收发数据
@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 func02():
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)
from fastapi import FastAPI
from fastapi import Response
import uvicorn
#创建fastapp框架对象
app=FastAPI()
#@app路由装饰器收发数据
# path相当于一个参数 当浏览器访问服务器的时候会把响应请求路径给到path
# path==> xxx.html
@app.get("/{path}")
# 这指定了函数的参数类型为str字符串类型
def func01(path:str):
with open(f"./html/html/{path}", "rb") as f:
file_data = f.read()
return Response(content=file_data,media_type="text/html")
#path ==> xxx.jpg
@app.get("/images/{path}")
def func02(path: str):
with open(f"./images/{path}", "rb") as f:
file_data = f.read()
return Response(content=file_data,media_type="jpg")
#运行服务器
uvicorn.run(app,host="127.0.0.1",port=8080)