Skip to content

Commit 4953ec6

Browse files
committed
update
1 parent ffdd020 commit 4953ec6

File tree

21 files changed

+473
-0
lines changed

21 files changed

+473
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from flask import *
2+
import sqlite3
3+
4+
app = Flask(__name__)
5+
6+
@app.route("/")
7+
def index():
8+
return render_template("index.html");
9+
10+
@app.route("/add")
11+
def add():
12+
return render_template("add.html")
13+
14+
@app.route("/savedetails",methods = ["POST","GET"])
15+
def saveDetails():
16+
msg = "msg"
17+
if request.method == "POST":
18+
try:
19+
name = request.form["name"]
20+
email = request.form["email"]
21+
address = request.form["address"]
22+
with sqlite3.connect("employee.db") as con:
23+
cur = con.cursor()
24+
#qry = "INSERT into students (name, email, address) values (?,?,?)",(name,email,address)
25+
#msg = qry
26+
#check the validity of data being send by user.
27+
cur.execute("INSERT into students (name, email, address) values (?,?,?)",(name,email,address))
28+
29+
con.commit()
30+
msg = " Student successfully Added "
31+
except:
32+
con.rollback()
33+
msg = " can not add the student to the list"
34+
finally:
35+
return render_template("success.html",msg = msg)
36+
con.close()
37+
38+
@app.route("/view")
39+
def view():
40+
con = sqlite3.connect("employee.db")
41+
con.row_factory = sqlite3.Row
42+
cur = con.cursor()
43+
cur.execute("select * from students ")
44+
rows = cur.fetchall()
45+
return render_template("view.html",rows = rows)
46+
47+
if __name__ == "__main__":
48+
app.run()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import sqlite3
2+
3+
conn = sqlite3.connect('employee.db')
4+
print "Opened database successfully";
5+
6+
conn.execute('CREATE TABLE students (name TEXT, addr TEXT, city TEXT, pin TEXT)')
7+
print "Table created successfully";
8+
conn.close()
9+
'''
10+
CREATE TABLE "students" (
11+
"name" TEXT,
12+
"email" TEXT,
13+
"address" TEXT,
14+
"ID" INTEGER NOT NULL UNIQUE,
15+
PRIMARY KEY("ID" AUTOINCREMENT)
16+
);
17+
'''
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head> <title>Add student </title> </head>
3+
<body>
4+
<h2>Student Information</h2>
5+
<form action = "/savedetails" method="post">
6+
<table>
7+
<tr><td>Name</td><td><input type="text" name="name"></td></tr>
8+
<tr><td>Email</td><td><input type="email" name="email"></td></tr>
9+
<tr><td>Address</td><td><input type="text" name="address"></td></tr>
10+
<tr><td><input type="submit" value="Submit"></td></tr>
11+
</table>
12+
</form>
13+
</body>
14+
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<html>
2+
<head> <title>home</title> </head>
3+
<body>
4+
<h2>welcome to the Student Management</h2>
5+
<a href="/add">Add Student data</a><br><br>
6+
<a href ="/view">List Records</a><br><br>
7+
<a href="/delete">Delete Record</a><br><br>
8+
</body>
9+
</html>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
3+
{{msg}}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<html>
2+
<head> <title>List</title> </head>
3+
<body>
4+
<h3>student Information</h3>
5+
6+
<table border=5>
7+
<thead> <td>ID</td> <td>Name</td> <td>Email</td> <td>Address</td>
8+
</thead>
9+
{% for i in rows %}
10+
<tr>
11+
<td> {{i["id"]}}
12+
<td> {{i[1]}}
13+
<td> {{i["email"]}}
14+
<td> {{i["address"]}}
15+
</tr>
16+
{% endfor %}
17+
</tr>
18+
</table>
19+
<br><br> <a href="/">Go back to home page</a> </body>
20+
</html>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from flask import *
2+
import sqlite3
3+
4+
app = Flask(__name__)
5+
6+
@app.route("/")
7+
def index():
8+
return render_template("index.html");
9+
10+
@app.route("/add")
11+
def add():
12+
return render_template("add.html")
13+
14+
@app.route("/savedetails",methods = ["POST","GET"])
15+
def saveDetails():
16+
msg = "msg"
17+
if request.method == "POST":
18+
try:
19+
name = request.form["name"]
20+
email = request.form["email"]
21+
address = request.form["address"]
22+
with sqlite3.connect("employee.db") as con:
23+
cur = con.cursor()
24+
#check the validity of data being send by user.
25+
cur.execute("INSERT into students (name, email, address) values (?,?,?)",(name,email,address))
26+
27+
con.commit()
28+
msg = " Student successfully Added "
29+
except:
30+
con.rollback()
31+
msg = " can not add the student to the list"
32+
finally:
33+
return render_template("index.html",msg = msg)
34+
con.close()
35+
36+
@app.route("/view")
37+
def view():
38+
con = sqlite3.connect("employee.db")
39+
con.row_factory = sqlite3.Row
40+
cur = con.cursor()
41+
cur.execute("select * from students ")
42+
rows = cur.fetchall()
43+
return render_template("view.html",rows = rows)
44+
45+
@app.route("/delete")
46+
def delete():
47+
con = sqlite3.connect("employee.db")
48+
con.row_factory = sqlite3.Row
49+
cur = con.cursor()
50+
cur.execute("select id,name from students ")
51+
rows = cur.fetchall()
52+
return render_template("delete.html",rows = rows)
53+
54+
@app.route("/deleterecord",methods = ["POST"])
55+
def deleterecord():
56+
id = request.form["id"]
57+
with sqlite3.connect("employee.db") as con:
58+
try:
59+
cur = con.cursor()
60+
cur.execute("delete from students where id = ?",id)
61+
msg = "record successfully deleted"
62+
except:
63+
msg = "can't be deleted"
64+
finally:
65+
return render_template("index.html",msg = msg)
66+
67+
68+
if __name__ == "__main__":
69+
app.run()
Binary file not shown.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<html>
2+
<head> <title>Add student </title> </head>
3+
<body>
4+
<h2>Student Information</h2>
5+
<form action = "/savedetails" method="post">
6+
<table>
7+
<tr><td>Name</td><td><input type="text" name="name"></td></tr>
8+
<tr><td>Email</td><td><input type="email" name="email"></td></tr>
9+
<tr><td>Address</td><td><input type="text" name="address"></td></tr>
10+
<tr><td><input type="submit" value="Submit"></td></tr>
11+
</table>
12+
</form>
13+
</body>
14+
</html>

0 commit comments

Comments
 (0)