-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflasks_test.py
88 lines (64 loc) · 1.96 KB
/
flasks_test.py
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
83
84
85
86
87
88
#coding=utf8
import sys
reload(sys)
sys.setdefaultencoding('utf8')
from flask import Flask, render_template, request, redirect, url_for
from flask_bootstrap import Bootstrap
import pymysql
from database_class import Database
app = Flask(__name__)
Bootstrap(app)
'''
@app.route('/')
def index():
return 'Index Page'
@app.route('/hello')
def hello():
return 'Hello World!'
@app.route('/gsq')
def home():
return render_template('index.html', name=None)
'''
@app.route('/')
def index():
'''
con = pymysql.connect(host="127.0.0.1",
user="root",
password="",
db="table",
charset='utf8')
cursor = con.cursor()
cursor.execute("SELECT * FROM STU")
results = cursor.fetchall()
con.close()
'''
sql = Database("table")
results = sql.execute("SELECT * FROM STU")
return render_template('test.html', name=None, results=results)
@app.route("/subm", methods=["GET", "POST"])
def submit():
if request.method == "POST":
name = request.form.get("name")
age = request.form.get("age")
_id = request.form.get("id")
if request.method == "GET":
name = request.args.get("name")
age = request.args.get("age")
_id = request.args.get("id")
'''
con = pymysql.connect(host="127.0.0.1",
user="root",
password="",
db="table",
charset='utf8')
cursor = con.cursor()
cursor.execute("INSERT INTO STU (`FIRST_NAME`, `AGE`, `ID`) VALUES('%s', %s, %s)" % (name, age, _id))
con.commit()
'''
#con.close()
sql = Database("table")
sql.execute("INSERT INTO STU (`FIRST_NAME`, `AGE`, `ID`) VALUES('%s', %s, %s)" % (name, age, _id))
return redirect(url_for('index'))
if __name__ == '__main__':
# 操作系统监听所有公网 IP
app.run(host='0.0.0.0', debug=True)