-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
120 lines (81 loc) · 3.33 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from flask import Flask,request,render_template,redirect
from flask_mysqldb import MySQL
import mysql.connector
import webbrowser
app=Flask(__name__)
app.config['MYSQL_HOST'] = 'localhost'
app.config['MYSQL_USER'] = 'root'
app.config['MYSQL_PASSWORD'] = ''
app.config['MYSQL_DB'] = 'foodbank'
cursor = mysql.connector.connect(
host="localhost",
user="root",
password="",
database="foodbank"
)
mysql = MySQL(app)
@app.route("/",methods=["GET","POST"])
def index():
if request.method=="GET":
cursor=mysql.connection.cursor()
cursor.execute('SELECT * FROM donor')
mydata=cursor.fetchall();
return render_template("index.html",data=mydata)
if request.method=="POST":
name=request.form["name"];
address=request.form["address"];
phone=request.form["phone"];
classes=request.form["classes"];
name1=request.form["name1"];
quantity1=request.form["quantity1"];
cursor=mysql.connection.cursor()
cursor.execute('''Insert INTO donor(Name,Address, Phone_Number,Food_Type,Item_Name,Quantity) Values(%s,%s,%s,%s,%s,%s)''',(name,address,phone,classes,name1,quantity1))
mysql.connection.commit();
return redirect("/")
@app.route("/req",methods=["GET","POST"])
def index1():
if request.method=="GET":
return render_template("request.html")
if request.method=="POST":
rname=request.form["rname"];
mno=request.form["mno"];
don=request.form["donation"];
add=request.form["add"];
needs=request.form["needs"];
cursor=mysql.connection.cursor();
cursor.execute('''INSERT INTO request(Name,No,Address,needs,item_Type) Values(%s,%s,%s,%s,%s)''',(rname,mno,add,needs,don))
mysql.connection.commit();
return redirect("/")
@app.route("/Donor",methods=["GET","POST"])
def l():
if request.method=="GET":
cursor=mysql.connection.cursor()
cursor.execute('SELECT * FROM donor')
mydata=cursor.fetchall();
return render_template("index.html",data=mydata)
if request.method=="POST":
name=request.form["name"];
address=request.form["address"];
phone=request.form["phone"];
classes=request.form["classes"];
name1=request.form["name1"];
quantity1=request.form["quantity1"];
rname=request.form["rname"];
mno=request.form["mno"];
don=request.form["dno"];
add=request.form["add"];
needs=request.form["needs"];
cursor=mysql.connection.cursor();
cursor2=mysql.connection.cursor();
cursor.execute('''Insert INTO donor(Name,Address, Phone_Number,Food_Type,Item_Name,Quantity) Values(%s,%s,%s,%s,%s,%s)''',(name,address,phone,classes,name1,quantity1))
cursor2.execute('''Insert INTO Request(Name,Address, No,needs,item_Type) Values(%s,%s,%s,%s,%s)''',(rname,mno,add,needs,don))
mysql.connection.commit();
return render_template("index.html")
@app.route("/maps")
def index3():
return render_template('foodbank.html')
@app.route("/tips")
def index4():
return render_template("tips.html")
if __name__ == '__main__':
app.run(debug=True)