diff --git a/src/api/routes.py b/src/api/routes.py index e7c1350..52739ec 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -37,8 +37,8 @@ async def read_root(request: Request): """主页面""" from fastapi.templating import Jinja2Templates import os - # 使用绝对路径确保模板目录正确 - templates_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "templates") + # 简化路径配置,直接使用当前工作目录下的templates文件夹 + templates_dir = os.path.join(os.getcwd(), "templates") templates = Jinja2Templates(directory=templates_dir) return templates.TemplateResponse("index.html", { "request": request, @@ -198,7 +198,8 @@ async def history_page(request: Request): """历史记录页面""" from fastapi.templating import Jinja2Templates import os - templates_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "templates") + # 简化路径配置,直接使用当前工作目录下的templates文件夹 + templates_dir = os.path.join(os.getcwd(), "templates") templates = Jinja2Templates(directory=templates_dir) return templates.TemplateResponse("history.html", { "request": request, @@ -217,7 +218,8 @@ async def result_page(request: Request, task_id: str): from fastapi.templating import Jinja2Templates import os - templates_dir = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "templates") + # 简化路径配置,直接使用当前工作目录下的templates文件夹 + templates_dir = os.path.join(os.getcwd(), "templates") templates = Jinja2Templates(directory=templates_dir) return templates.TemplateResponse("result.html", { "request": request,