-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart4_db.py
63 lines (46 loc) · 1.43 KB
/
part4_db.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
import sqlite3
from flask import Flask, render_template, request
app = Flask(__name__)
@app.route('/')
@app.route('/index')
@app.route('/home')
def home():
return 'hello from flask'
@app.route('/greeting', methods=['GET', 'POST'])
def greet():
message = None
if request.method == 'POST':
name = request.form['std_name']
if name:
message = 'Hello ' + name
else:
message = 'Hello student'
return render_template('mygreeting.html', message=message)
@app.route('/students')
def std():
# nested dictionary
students = {
'120191122': {'name': 'ahmed', 'dept': 'MM'},
'120192233': {'name': 'Mohammad', 'dept': 'MM'},
'220192233': {'name': 'Noor', 'dept': 'Mobi'}
}
return render_template('students.html', students=students)
@app.route('/list_students')
def list_std():
# nested dictionary
students = {
'120191122': {'name': 'Ahmed', 'dept': 'MM'},
'120192233': {'name': 'Mohammad', 'dept': 'MM'},
'120193344': {'name': 'Abderrahman', 'dept': 'Commerce'}
}
return render_template('list_students.html', students=students)
@app.route('/std_db')
def std_db():
conn = sqlite3.connect('students.sqlite')
cur = conn.cursor()
cur.execute('''select * from student_info''')
rows = cur.fetchall()
# print(rows)
return render_template('std_db.html', rows=rows)
if __name__ == '__main__':
app.run()