Python 烧瓶页面未显示其应显示的内容
post页面也必须显示传递给它的post,但它只显示继承给它的布局 routes.pyPython 烧瓶页面未显示其应显示的内容,python,flask,Python,Flask,post页面也必须显示传递给它的post,但它只显示继承给它的布局 routes.py @app.route("/post/<int:post_id>") def post(post_id): post = Post.query.get_or_404(post_id) return render_template('post.html', title=post.title, post=post) @app.route(“/post/”) def
@app.route("/post/<int:post_id>")
def post(post_id):
post = Post.query.get_or_404(post_id)
return render_template('post.html', title=post.title, post=post)
@app.route(“/post/”)
def post(post_id):
post=post.query.get\u或\u 404(post\u id)
返回呈现模板('post.html',title=post.title,post=post)
post.html
{% block content %}
{% for post in posts %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ url_for('static', filename='pictures/' + post.author.image_file) }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ post.author.username }}</a>
<small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small>
</div>
<h2 class="article-title">{{ post.title }}</h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
{% endfor %}
{% endblock content %}```
{%block content%}
{posts%%中的post为%s}
{{post.date_post.strftime(“%Y-%m-%d”)}
{{post.title}}
{{post.content}
{%endfor%}
{%endblock内容%}```
如果不需要html页面中的for循环,请从替换您的post.html
{% block content %}
{% for post in posts %}
<article class="media content-section">
<img class="rounded-circle article-img" src="{{ url_for('static', filename='pictures/' + post.author.image_file) }}">
<div class="media-body">
<div class="article-metadata">
<a class="mr-2" href="#">{{ post.author.username }}</a>
<small class="text-muted">{{ post.date_posted.strftime('%Y-%m-%d') }}</small>
</div>
<h2 class="article-title">{{ post.title }}</h2>
<p class="article-content">{{ post.content }}</p>
</div>
</article>
{% endfor %}
{% endblock content %}
{%block content%}
{posts%%中的post为%s}
{{post.date_post.strftime(“%Y-%m-%d”)}
{{post.title}}
{{post.content}
{%endfor%}
{%endblock内容%}
致:
{%block content%}
{{post.date_post.strftime(“%Y-%m-%d”)}
{{post.title}}
{{post.content}
{%endblock内容%}```
当模板使用
{% for post in posts %}
它期望posts
是一个包含单个posts的Iterable(例如,列表)
路由正在post
中向模板传递一个post。由于没有传递模板posts
,因此它将将其视为空列表
删除循环的
,但不要删除其内容。您希望如何显示它,以及它当前如何显示?
{% for post in posts %}