https://study.163.com/course/courseLearn.htm?courseId=1005913008&from=study#/learn/video?lessonId=1053446514&courseId=1005913008
学习了flask的基本知识,做下笔记
首先创建项目后在编辑结构里勾选上单一实例和DEBUG。
1 from flask import Flask, render_template, request, redirect 2 3 app = Flask(__name__) 4 5 6 @app.route('/') 7 def hello_world(): 8 # 通过url传递参数 9 wd = request.args.get('wd') 10 age = request.args.get('age') 11 print(wd) 12 print(age) 13 return '好好学习'+wd 14 15 16 @app.route('/index', methods=['GET', 'POST']) 17 def index(): 18 # 表单参数传递 19 if request.method == 'GET': 20 return render_template('index.html') 21 else: 22 tel = request.form.get('tel') 23 pwd = request.form.get('pwd') 24 print('tel:%s'%tel) 25 print('pwd:%s'%pwd) 26 # 重定向 27 return redirect('/profile/') 28 29 30 @app.route('/profile/') 31 def profile(): 32 return "个人中心页面" 33 34 35 if __name__ == '__main__': 36 app.run()
index的代码
<body> <img src="{{ url_for('static',filename='ss.jpg') }}"> <h1>登录窗口界面</h1> <form action="" method="post"> <input type="text" name="tel"> <input type="password" name="pwd"> <button>登录</button> </form> </body>