- 新建Flask项目。
- 设置调试模式。
- 理解Flask项目主程序。
- 使用装饰器,设置路径与函数之间的关系。
- 使用Flask中render_template,用不同的路径,返回首页、登录员、注册页。
- 用视图函数反转得到URL,url_for(‘login’),完成导航里的链接。
1 from flask import Flask,render_template
2
3 app=Flask(__name__)
4
5 @app.route('/')
6 def index():
7 return render_template('index.html')
8
9 @app.route('/login/')
10 def login():
11 return render_template('login.html')
12
13 @app.route('/enroll/')
14 def enroll():
15 return render_template('enroll.html')
16
17
18 if __name__ == '__main__':
19 app.run(debug=True)
1 <a href="{{ url_for('index') }}">首页</a>
2 <a href="{{ url_for('login') }}">登录</a>
3 <a href="{{ url_for('enroll') }}">注册</a>