-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
43 lines (36 loc) · 986 Bytes
/
app.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
from flask import Flask
from helper import pets
app = Flask(__name__)
@app.route('/')
def index():
return '''
<h1>Adopt a Pet!</h1>
<p>Browse through the links below to find your new furry friend:</p>
<ul>
<li><a href="animals/dogs">Dogs</a></li>
<li><a href="animals/cats">Cats</a></li>
<li><a href="animals/rabbits">Rabbits</a></li>
</ul>
'''
@app.route("/animals/<pet_type>")
def animals(pet_type):
html = f"<h1>List of {pet_type}</h1>"
html += "<ul>"
for idx, item in enumerate(pets[pet_type]):
html += "<li>" + \
f'<a href="/animals/{pet_type}/{idx}">' + \
item["name"] + "</a></li>"
html += "</ul>"
return html
@app.route("/animals/<pet_type>/<int:pet_id>")
def pet(pet_type, pet_id):
pet = pets[pet_type][pet_id]
return f'''
<h1>{pet['name']}</h1>
<img src="{pet['url']}">
<p>{pet['description']}</p>
<ul>
<li>{pet['breed']}</li>
<li>{pet['age']}</li>
</ul>
'''