-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojet.py
More file actions
27 lines (22 loc) · 1.03 KB
/
projet.py
File metadata and controls
27 lines (22 loc) · 1.03 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
from flask import Flask, render_template, request, redirect, url_for, flash, jsonify
app = Flask(__name__)
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from database_setup import Base, Restaurant, MenuItem
engine = create_engine('sqlite:///restaurantmenu.db')
Base.metadata.bind = engine
DBSession = sessionmaker(bind=engine)
session = DBSession()
@app.route('/restaurants/<int:restaurant_id>/menu/JSON')
def restaurantMenuJson(restaurant_id):
restaurant = session.query(Restaurant).filter_by(id = restaurant_id).one()
items = session.query(MenuItem).filter_by(restaurant_id = restaurant_id).all()
return jsonify(MenuItems=[item.serialize for item in items])
@app.route('/restaurants/<int:restaurant_id>/menu/<int:menu_id>/JSON')
def restaurantMenuItemJson(restaurant_id,menu_id):
item = session.query(MenuItem).filter_by(id = menu_id).one()
return jsonify(MenuItem=item.serialize)
if __name__ == '__main__':
app.debug = True
app.secret_key = 'super_secret_key'
app.run(host='0.0.0.0', port=5000)