-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequestUsing.py
More file actions
83 lines (68 loc) · 1.82 KB
/
requestUsing.py
File metadata and controls
83 lines (68 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Aug 12 21:03:16 2019
@author: liutingting16
"""
#%% test1
#from flask import Flask,request
#
#app = Flask(__name__)
#
#@app.route('/login')
#def login():
# uname = request.form.get("name")
# return uname
#
#if __name__=="__main__":
# #app.run(host="127.0.0.1",port="80",debug=True) ##app.run(host='ip', port='端口')
# app.run()
#%% test2
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
def hello_world():
return render_template('index.html')
@app.route('/search/')
def search():
l = request.args.get('q')
return '用户提交的参数是: %s' % l
@app.route('/login/', methods=['GET','POST'])
def login():
if request.method == 'GET':
username = request.args.get('username')
password = request.args.get('password')
print('username:', username)
print('password', password)
return 'login get success'
#return render_template('login.html')
else:
username = request.form.get('username')
password = request.form.get('password')
print('username:', username)
print('password', password)
return 'login success'
if __name__ == '__main__':
app.run(debug=True)
#1)GET 请求 :通过"flask.request.args"来获取
#2)POST 请求 :通过"flask.reques.form"来获取
#%% test3 - 可执行
#from flask import Flask, render_template, request
#
#app = Flask(__name__)
#
#
#@app.route('/')
#def index():
# print(type(request.query_string))
# return render_template('frame.html')
#
#
#@app.route('/', methods=['POST'])
#def post():
# if request.form['name'] == 'a' and request.form['password'] == 'a':
# return '欢迎' + request.form['name']
# else:
# return '用户名密码错误'
#
#app.run()