嵌入YouTube视频Jinja2 Flas

2024-03-28 10:09:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试在我的Flask应用程序中添加一个嵌入的YouTube视频。在

数据库存储YouTube的URL

这是我的模型:

class Post(db.Model):
    id = db.Column(db.Integer, primary_key = True)
    video = db.Column(db.String(450))

@app.route('/post/<id>')
def post(id):
    post = Post.query.filter_by(id=id).first()
    return render_template('post.html', post = post)

我的模板:

^{pr2}$

示例:

数据库中存储的URL:

id|video
1 |https://www.youtube.com/watch?v=Q5XvLJrW6Fg

在web浏览器中呈现:

<iframe src="https://www.youtube.com/watch?v=Q5XvLJrW6Fg" allowfullscreen="" width="100%" frameborder="0"></iframe>

但不能显示视频。在


Tags: httpscomid数据库urldb视频youtube