-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.py
76 lines (43 loc) · 1.62 KB
/
App.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
64
65
66
67
68
69
70
71
72
73
74
75
76
from flask import Flask, render_template, request, redirect, url_for, flash
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.secret_key = "Secret Key"
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:''@localhost/crud'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
class Data(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100))
email = db.Column(db.String(100))
phone = db.Column(db.String(100))
def __init__(self, name, email, phone):
self.name = name
self.email = email
self.phone = phone
@app.route('/')
def Index():
all_data = Data.query.all()
return render_template("index.html",employees = all_data)
@app.route('/insert',methods = ['POST'])
def insert():
if request.method == 'POST':
name = request.form['name']
email = request.form['email']
phone = request.form['phone']
my_data = Data(name,email,phone)
db.session.add(my_data)
db.session.commit()
flash("Employee Inserted Sucessfully")
return redirect(url_for('Index'))
@app.route('/update',methods = ['GET','POST'])
def update():
if request.method == 'POST':
my_data = Data.query.get(request.form.get('id'))
my_data.name = request.form['name']
my_data.email = request.form['email']
my_data.phone = request.form['phone']
db.session.commit()
flash("Employee Upated Sucessfully")
return redirect(url_for('Index'))
if __name__ == "__main__":
app.run(debug=True)