-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlisting_menu_items.py
More file actions
37 lines (32 loc) · 1.02 KB
/
listing_menu_items.py
File metadata and controls
37 lines (32 loc) · 1.02 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
# it is simple flask example
from flask import Flask
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Restaurant, MenuItem
app = Flask(__name__)
engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
@app.route('/restaurants/<int:restaurant_id>/')
def restaurantMenu(restaurant_id):
restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
print restaurant.name
print restaurant.id
items = session.query(MenuItem).filter_by(restaurant_id=restaurant.id)
output = ''
for i in items:
print i.description
print i.price
print i.name
output += i.name
output += '</br>'
output += str(i.price)
output += '</br>'
output += str(i.description)
output += '</br>'
output += '</br>'
return output
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5000)