我在Vue中构建了我的应用程序,在Python中使用FastAPI构建了我的后端。完成npm run build
之后,我将dist
文件夹复制到templates
文件夹中。我想加载index.html
,但我得到了错误error_aborted 404 (not found)
。static
文件夹位于templates
文件夹内。为什么我会犯这个错误
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
app = FastAPI()
templates = Jinja2Templates(directory="templates")
app.mount("/static", StaticFiles(directory="templates"))
@app.get("/")
def serve_home(request: Request):
return templates.TemplateResponse("index.html", context= {"request": request})
我还尝试了以下代码,并将dist
文件夹放在static
文件夹中,没有templates
文件夹
@app.get("/")
async def index():
return FileResponse('static/index.html', media_type='text/html')
替换此项:
为此:
相关问题 更多 >
编程相关推荐