【发布时间】:2021-05-09 14:00:54
【问题描述】:
该网站能够显示博客的全部内容,但不能显示视频内容。当我尝试发布包含视频的新帖子时。它只是显示 html 脚本。反正有没有从python传递整个html?
我正在使用 post.content 将帖子内容传递到 html 页面。它适用于文本,但不适用于图像或视频。
home.html:
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="{{ url_for('users.user_posts', username=post.author.username)}}">{{ post.author.username }}</a>
<small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small>
</div>
<h2><a class="article-title" href="{{ url_for('posts.post',post_id=post.id) }}">{{ post.title }}</a></h2>
<div class="article-content"><{{ post.content }}></div>
</div>
Routes.py
def home():
page = request.args.get('page', 1, type=int)
posts = Post.query.order_by(Post.date_posted.desc()) \
.paginate(page=page, per_page=5)
return render_template('home.html', posts=posts)
【问题讨论】:
-
内容呈现为文本以防止Javascript注入攻击。
标签: python-3.x flask