-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnet1.py
More file actions
86 lines (68 loc) · 2.43 KB
/
connet1.py
File metadata and controls
86 lines (68 loc) · 2.43 KB
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
from flask import Flask, render_template, request
import sqlite3 as sql
import time
from waitress import serve
from flask_compress import Compress
app = Flask(__name__)
#COMPRESS_MIMETYPES=['text/html', 'text/css', 'application/json']
#COMPRESS_LEVEL=6
#COMPRESS_MIN_SIZE=500
#Compress(app)
@app.route('/')
def home():
return render_template('home.html')
#return ' <html lang="en"><head><meta charset="UTF-8"><title>Home</title></head><body><a href="/">add new record</a><br><a href="/">Show lists</a></body></html> '
@app.route('/student')
def new_student():
return render_template('student.html')
@app.route('/addrec', methods=['GET', 'POST'])
def addrec():
if request.method == 'POST':
try:
Id = request.form['Id']
nm = request.form['nm']
with sql.connect("student.db") as con:
cur = con.cursor()
#cur.execute("CREATE TABLE STUDENT (Id INTEGER, Name TEXT)")
cur.execute("INSERT INTO STUDENT(Id,Name) VALUES (?,?)", (Id, nm))
con.commit()
msg = "Record added successfully"
except Exception as msg1:
con.rollback()
#msg = "error in inserting"
msg=msg1
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")
rows = cur.fetchall()
return render_template('list.html', rows=rows)
@app.route("/delete")
def delete():
return render_template("delete.html")
@app.route("/deleterecord",methods = ["POST"])
def deleterecord():
Id = request.form["Id"]
with sql.connect('student.db') as con:
try:
cur = con.cursor()
#n=cur.execute("SELECT * FROM TABLE WHERE Id - ?",Id)
#msg=n
cur.execute("delete from STUDENT where Id = ?",Id)
msg = "record successfully deleted"
con.commit()
except Exception as msg1:
msg = msg1
finally:
return render_template("deleterecord.html",msg = msg)
#con.close()
if __name__ == "__main__":
app.run(debug=True, threaded=True)
#app.jinja_env.cache={}
#serve(app, host = '0.0.0.0', threads=100, port = 8000)
#time.sleep(1)