上一章节是做到了在本地浏览器上打印出hello,world
如果你要更加复杂,可以像下面一样在return结果里添加内容
但是!!简单的几句话你可以这么写,要是整的一个网页,你可没法把代码都拖在return后面吧
所以,后面引入了模板功能
模板:
模板的位置放在templates文件夹下面,一般是html文件,我们把index.html改动成如下样式
<html>
<head>
<title>{
{title}} - microblog</title>
</head>
<body>
<h1>Hello, {
{user.nickname}}!</h1>
</body>
</html>
其中: {
{}}表示这是一个变量,可以根据用户在模块端给予的参数的不同,进行调整
下面的程序就是调用了 render_template模板
from flask importrender_template
from app importapp
@app.route('/')
@app.route('/index')
def index():
user = {