为什么需要模板?
考虑以下需求:在我的主页上显示html的标题,可以这么做:
from flask import Flask
app = Flask(__name__)
@app.route('/')
@app.route('/index')
def index():
user = {'nickname': 'Joshua'} # 占位对象,ugly!
return '''
<html>
<head>
<title>Home Page</title>
</head>
<body>
<h1>Hello, ''' + user['nickname'] + '''</h1>
</body>
</html>
'''
if __name__ == '__main__':
app.run()
Refer: http://blog.miguelgrinberg.com/post/the-flask-mega-tutorial-part-ii-templates