I just ended the “Adopt a Pet” Project and it went fine… at least on Codecademy platform.
I usually do the projects parallel in VSCode but this time the last two steps don’t work out and I don’t know where the mistake is.
Here’s my code:
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 index, i in enumerate(pets[pet_type]):
html += f"<li><a href='/animals/{pet_type}/{index}'>{i['name']}</a></li>"
html += "</ul>"
return html
@app.route("/animals/<pet_type>/<int:pet_id>") # The Error occurs with this route!
def pet(pet_type, pet_id):
pet = pets[pet_type][pet_id]
return f"<h1>{pet['name']}</h1>"
if __name__ == '__main__':
app.run()
as I said, in codecademy it works and I can call the individual sites for the pets like “…localhost/animals/dogs/0” for Spot
But when I run this code in my Terminal and go to my localhost it always gives me a 404 Not Found when I try to enter a pet’s site.
“…/animals/dogs” still works but “…/animals/dogs/0” (or any other animal and id) gives the 404 Error.
I did not copy the code the first time, instead I wrote it new. After the issue I copied the code 1:1 from codecademy and it just still doesn’t work
Does anyone has an idea what I’m missing here?
Thanks