静态文件配置
import os
from pathlib import Path
from fastapi import FastAPI
import uvicorn
from fastapi.staticfiles import StaticFiles
app = FastAPI()
base_dir = os.path.dirname(os.path.abspath(__file__))
static_file_path = Path(base_dir, './static')
# mount表示将某个目录下一个完全独立的应用挂载过来,这个不会在API交互中显示
app.mount(path="/static", app=StaticFiles(directory=static_file_path))
if __name__ == '__main__':
uvicorn.run('main:app', host='0.0.0.0', port=8000, reload=True,
debug=True, workers=1)
原创文章,作者:,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/270490.html