[Introduction to Flask] Adopt a Pet Project - Task 16

Hello everyone. I am stuck on task 16 on Adopt a Pet project. I have checked previous posts on this issue before and I cant seem to get the answer. Its probably simple and I just need another pair of eyes to find the issue. When I click on the links of the names of the pets I am met with a ‘Not Found’ page.

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 = html + '<ul>'
  for index, pet in enumerate(pets[pet_type]):
    name = pet['name']
    html += '<li><a href = "/animals/{pet_type}/{index}">' + 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]
  pet_name = pet["name"]
  
  return f'''<h1>{pet_name}</h1>'''```

link to exercise:
https://www.codecademy.com/courses/learn-flask/projects/adopt-a-pet

link to Gist (where my code is):
https://gist.github.com/codecademydev/c61de63f1b99ac1c9b3e11fcd61736eb

You can use debug statements. Also what is the route that was note found, what was the url? If the pet is not in a database, it will not be able to be accessed.

The url that is not found is “/animals/{pet_type}/{index}” on line 23.

Is it literally that or is it resolving to something concrete like /animals/dog/3. Because if it’s not then that’s your problem.

So when I click on the link, the url on the browser appears as the following “animals/%7Bpet_type%7D/%7Bindex%7D”. Not sure why its becoming/resolving like that. I want it to resolve to something like ‘/animals/dogs/2’.

Nevermind, I found the solution. It was to add the format (f) to line 23. Thought the f in line 19 would be enough but I was wrong. So the correction is

html += f'<li><a href = "/animals/{pet_type}/{index}">' + name + '</a></li>'