[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__)

def index():
  return '''<h1>Adopt a Pet!</h1>
  <p>Browse through the links below to find your new furry friend:</p>
  <li><a href='/animals/dogs'>Dogs</a></li>
  <li><a href='/animals/cats'>Cats</a></li>
  <li><a href='/animals/rabbits'>Rabbits</a></li>

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

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:

link to Gist (where my code is):

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>'