-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdemo.py
49 lines (38 loc) · 1.3 KB
/
demo.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
from flask import Flask, render_template, request
import sqlite3 as sql
app = Flask(__name__)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/enternew')
def new_student():
return render_template('student.html')
@app.route('/addrec',methods = ['POST', 'GET'])
def addrec():
if request.method == 'POST':
try:
rn=request.form['rn']
nm = request.form['nm']
dept = request.form['dpt']
sem = request.form['sem']
with sql.connect("student.db") as con:
cur = con.cursor()
cur.execute("INSERT INTO student_det (reg_no,name,dept,sem) VALUES (?,?,?,?)",(rn,nm,dept,sem) )
con.commit()
msg = "Record successfully added"
except:
con.rollback()
msg = "error in insert operation"
finally:
return render_template("result.html",msg = msg)
con.close()
@app.route('/list')
def list():
con = sql.connect("student.db")
con.row_factory = sql.Row
cur = con.cursor()
cur.execute("select * from student_det")
rows = cur.fetchall();
return render_template("list.html",rows = rows)
if __name__ == '__main__':
app.run(debug = True)