-
Notifications
You must be signed in to change notification settings - Fork 0
/
foo7.py
39 lines (29 loc) · 879 Bytes
/
foo7.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
import sqlite3
from flask import Flask, render_template
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route('/list_std')
def list_std():
# nested dictionary
students = {
'120191122': {'name': 'Ahmed', 'dept': 'MM'},
'120192233': {'name': 'Mohammad', 'dept': 'MM'},
'220193344': {'name': 'Fatima', 'dept': 'MM'}
}
return render_template('list_std007.html', students=students)
@app.route('/std_db')
def std_db():
# step 1: connect to db
conn = sqlite3.connect('std1.sqlite')
# step 2: create a cursor
cur = conn.cursor()
# step 3: execute SQL statement
cur.execute('''select * from std_info''')
# step 4: fetch
rows = cur.fetchall()
# print(rows)
return render_template('std_db07.html', rows=rows)
if __name__ == '__main__':
app.run(debug=True)