-
Notifications
You must be signed in to change notification settings - Fork 0
/
hbnb.py
executable file
·48 lines (36 loc) · 1.23 KB
/
hbnb.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
#!/usr/bin/python3
""" Starts a Flask Web Application """
from models import storage
from models.state import State
from models.city import City
from models.amenity import Amenity
from models.place import Place
import uuid
from os import environ
from flask import Flask, render_template
app = Flask(__name__)
@app.teardown_appcontext
def close_db(error):
""" Remove the current SQLAlchemy Session """
storage.close()
@app.route('/hbnb/', strict_slashes=False)
def hbnb():
""" HBNB is alive! """
states = storage.all(State).values()
states = sorted(states, key=lambda k: k.name)
st_ct = []
for state in states:
st_ct.append([state, sorted(state.cities, key=lambda k: k.name)])
amenities = storage.all(Amenity).values()
amenities = sorted(amenities, key=lambda k: k.name)
places = storage.all(Place).values()
places = sorted(places, key=lambda k: k.name)
cache_id = str(uuid.uuid4())
return render_template('index.html',
states=st_ct,
amenities=amenities,
places=places,
cache_id=uuid.uuid4())
if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5001)