-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
96 lines (76 loc) · 2.76 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
import os
from flask import Flask, request, jsonify, render_template
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
app.config.from_object("config.DevelopmentConfig")
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = SQLAlchemy(app)
from models import Product, Category
@app.route("/")
def hello():
return render_template('start.html')
@app.route("/product/getall")
def get_all():
try:
product=Product.query.all()
products = [dict(e.serialize()) for e in product]
return render_template('home.html',products = products)
except Exception as e:
return(str(e))
@app.route("/product/getid/<id_>")
def get_prod_by_id(id_):
try:
product=Product.query.filter_by(id=id_).first()
products = [dict(product.serialize())]
return render_template('home.html',products=products)
except Exception as e:
return(str(e))
@app.route("/product/getseller/<seller_>")
def get_prod_by_seller(seller_):
try:
product=Product.query.filter_by(seller=seller_)
products = [dict(e.serialize()) for e in product]
return render_template('home.html',products=products)
except Exception as e:
return(str(e))
@app.route("/product/getcategory/<catid_>")
def get_prod_by_category(catid_):
try:
product=Product.query.filter_by(cat_id=catid_)
products = [dict(e.serialize()) for e in product]
return render_template('home.html',products=products)
except Exception as e:
return(str(e))
@app.route("/product/<sql_>")
def get_prod_by_sql(sql_):
try:
if 'drop' not in sql_.lower() and 'insert' not in sql_.lower() and 'delete' not in sql_.lower() and 'create' not in sql_.lower():
result = db.engine.execute(sql_)
return render_template('home.html',products=result)
else:
return render_template('error.html')
except Exception as e:
return(str(e))
@app.route("/category/getid/<id_>")
def get_cat_by_id(id_):
try:
cat=Category.query.get(id_)
cats = [dict(cat.serialize())]
return render_template('category.html',products=cats)
except Exception as e:
return(str(e))
@app.route("/category/<sql_>")
def get_cat_by_sql(sql_):
try:
if 'drop' not in sql_.lower() and 'insert' not in sql_.lower() and 'delete' not in sql_.lower() and 'create' not in sql_.lower():
result = db.engine.execute(sql_)
return render_template('category.html',products=result)
else:
return render_template('error.html')
except Exception as e:
return(str(e))
@app.route("/presentation")
def present():
return render_template('presentation.html')
if __name__ == '__main__':
app.run()