Python 双卷背带(金甲2)在烧瓶中不起作用
我是网络开发新手,遇到了这个非常烦人的问题 以下是我的app.py代码:Python 双卷背带(金甲2)在烧瓶中不起作用,python,html,flask,Python,Html,Flask,我是网络开发新手,遇到了这个非常烦人的问题 以下是我的app.py代码: from flask import Flask, render_template app = Flask(__name__) all_posts = [ { 'Title': 'Post 1.', 'Content': 'Content in Post 1.' }, { 'Title': 'Post 2.', 'Content':
from flask import Flask, render_template
app = Flask(__name__)
all_posts = [
{
'Title': 'Post 1.',
'Content': 'Content in Post 1.'
},
{
'Title': 'Post 2.',
'Content': 'Content in Post 2.'
}
]
@app.route('/posts')
def posts():
return render_template('posts.html', posts=all_posts)
all_posts变量被发送到posts.html
下面是posts.html代码:
{% extends 'base.html' %}
{% block head%}
<title>Posts</title>
{% endblock %}
{% block body%}
<h1>All Posts</h1>
{% for post in posts %}
<h2> {{post.title}} </h2>
<p> {{post.content}} </p>
{% endfor %}
{% endblock %}
{%extends'base.html%}
{%block head%}
帖子
{%endblock%}
{%block body%}
所有职位
{posts%%中的post为%s}
{{post.title}
{{post.content}
{%endfor%}
{%endblock%}
但是,当我在浏览器中运行/posts时,双大括号内的任何内容都不会显示。非常感谢您的帮助。模板变量区分大小写。请尝试以下操作:
{% extends 'base.html' %}
{% block head%}
<title>Posts</title>
{% endblock %}
{% block body%}
<h1>All Posts</h1>
{% for post in posts %}
<h2> {{post.Title}} </h2>
<p> {{post.Content}} </p>
{% endfor %}
{% endblock %}
{%extends'base.html%}
{%block head%}
帖子
{%endblock%}
{%block body%}
所有职位
{posts%%中的post为%s}
{{post.Title}
{{post.Content}
{%endfor%}
{%endblock%}
moveall_posts
def posts()中的数组:功能块