forked from jzamora5/AirBnB_clone_v3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path8-cities_by_states.py
executable file
·41 lines (33 loc) · 1.22 KB
/
8-cities_by_states.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
#!/usr/bin/python3
""" Starts a Flash Web Application """
from models import storage
from models.state import State
from os import environ
from flask import Flask, render_template
app = Flask(__name__)
# app.jinja_env.trim_blocks = True
# app.jinja_env.lstrip_blocks = True
@app.teardown_appcontext
def close_db(error):
""" Remove the current SQLAlchemy Session """
storage.close()
@app.route('/states_list', strict_slashes=False)
def states_list():
""" displays a HTML page with a list of states """
states = storage.all(State).values()
states = sorted(states, key=lambda k: k.name)
return render_template('7-states_list.html', states=states)
@app.route('/cities_by_states', strict_slashes=False)
def cities_list():
""" displays a HTML page with a list of cities by states """
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)])
return render_template('8-cities_by_states.html',
states=st_ct,
h_1="States")
if __name__ == "__main__":
""" Main Function """
app.run(host='0.0.0.0', port=5000)