-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouting_template_quiz.py
More file actions
58 lines (47 loc) · 1.78 KB
/
routing_template_quiz.py
File metadata and controls
58 lines (47 loc) · 1.78 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# how to do routing using /<int:restautrant_id>/
from flask import Flask, render_template,url_for
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('/')
@app.route('/restaurants/<int:restaurant_id>/')
def restaurantMenu(restaurant_id):
restaurant = session.query(Restaurant).filter_by(id=restaurant_id).one()
items = session.query(MenuItem).filter_by(restaurant_id=restaurant.id)
return render_template('menu.html', restaurant=restaurant, items=items)
"""
output = ''
for i in items:
output += '<b>'
output += i.restaurant.name
output +='</b>'
output += '</br>'
output += i.name
output += '</br>'
output += i.price
output += '</br>'
output += i.description
output += '</br>'
output += '</br>'
return output
"""
# Task 1: Create route for newMenuItem function here
@app.route('/restaurant/<int:restaurant_id>/new')
def newMenuItem(restaurant_id):
return "page to create a new menu item. Task 1 complete!"
# Task 2: Create route for editMenuItem function here
@app.route('/restaurant/<int:restaurant_id>/<int:menu_id>/edit')
def editMenuItem(restaurant_id, menu_id):
return "page to edit a menu item. Task 2 complete!"
# Task 3: Create a route for deleteMenuItem function here
@app.route('/restaurant/<int:restaurant_id>/<int:menu_id>/delete')
def deleteMenuItem(restaurant_id, menu_id):
return "page to delete a menu item. Task 3 complete!"
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0', port=5000)