Flask render_template用法
示例
Flask允许您将模板用于动态网页内容。使用模板的示例项目结构如下:
myproject/
/app/
/templates/
/index.html
/views.pyviews.py:
from flask import Flask, render_template
app = Flask(__name__)
@app.route("/")
def index():
pagetitle = "HomePage"
return render_template("index.html",
mytitle=pagetitle,
mycontent="Hello World")请注意,可以通过将键/值对附加到render_templates函数来将动态内容从路由处理程序传递到模板。在上面的示例中,“pagetitle”和“mycontent”变量将传递到模板以包含在呈现的页面中。将这些变量包括在模板中,并用双括号括起来:{{mytitle}}
index.html:
<html>
<head>
<title>{{ mytitle }}</title>
</head>
<body>
<p>{{ mycontent }}</p>
</body>
</html>与第一个示例相同地执行时,http://localhost:5000/标题将为“HomePage”,段落的内容为“HelloWorld”。
热门推荐
10 八一幼儿祝福语大全简短
11 公司乔迁食堂祝福语简短
12 婚礼结束聚餐祝福语简短
13 儿媳买车妈妈祝福语简短
14 毕业送礼老师祝福语简短
15 同事辞职正常祝福语简短
16 恭贺新婚文案祝福语简短
17 金店立秋祝福语简短英文
18 婆婆高寿祝福语大全简短