-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
61 lines (55 loc) · 1.55 KB
/
app.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
from flask import Flask, render_template
import pymysql
import time
app = Flask(__name__)
# Cấu hình kết nối MySQL
db_config = {
'host': 'localhost',
'user': 'root',
'password': 'khang',
'database': 'creditcard',
}
@app.route('/')
def index():
# Kết nối đến MySQL
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
return render_template('index.html')
@app.route('/demo1')
def demo1():
# Kết nối đến MySQL
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
# Thực hiện truy vấn
try:
cursor.execute("SELECT * FROM new_transaction")
data = cursor.fetchall()
except:
data = []
pass
# Xuất ra trang HTML
return render_template('demo1.html', data=data)
@app.route('/demo2')
def demo2():
# Kết nối đến MySQL
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
# Thực hiện truy vấn
try:
cursor.execute("SELECT * FROM new_transaction")
data = cursor.fetchall()
except:
data = []
pass
# Xuất ra trang HTML
return render_template('demo2.html', data=data)
@app.route('/customer/<cc_num>')
def show_cust(cc_num):
# Kết nối đến MySQL
connection = pymysql.connect(**db_config)
cursor = connection.cursor()
cursor.execute(f"SELECT * FROM customer WHERE customer.cc_num = {cc_num}")
data = cursor.fetchall()
return render_template('cust.html', data=data)
if __name__ == '__main__':
app.run(debug=True)