我正在Python上使用fastapi设计一个网站,并在其中一个页面上显示视频。
这是我的test.py代码:
from fastapi import FastAPI, Request
from fastapi.responses import StreamingResponse
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
app = FastAPI()
app.mount("/static", StaticFiles(directory="static"), name="static")
templates = Jinja2Templates(directory="templates")
@app.get("/")
async def read_root(request: Request):
video_url = '/static/videos/test.mp4'
return templates.TemplateResponse("edit.html", {"request": request,'video_url':video_url})
这是我的html代码:
<!DOCTYPE html>
<html>
<head>
<title>TESTING</title>
</head>
<body>
<video width="600" height="300" controls>
<source src="{{ video_url }}" type="video/mp4">
</video>
</body>
</html>
我想要的功能之一是视频搜索。如果我尝试在没有fastapi的情况下显示视频,那么查找非常有效,但有了fastapi就不行了。有人能给我建议解决方案吗?