Help With Introduction to Flask's "Adopt a Pet" Project

Hi again!

In the forums it’s not policy to give away answers. But if you have specific problems within the exercise that you’re stuck on, you can ask away! :slight_smile: Just remember to format the code with </> and paste any error messages as well.

I’ve been stuck in this for 2 days. Help me solve the steps from 14 to 17.

I’ve done the steps, But I dont’t know whether it is right or wrong.

Help me finish this project.

Thank You.

This seems like a matter of dealing with dictionaries.

For example:

bread = {}
bread["type"] = "pita"
bread["origin"] = "middle-east"

print(bread)
# {'type': 'pita', 'origin': 'middle-east'}
print(bread["type"])
# pita

So all you need to do is:

  • within an h1 element
  • access the name key of pet
  • return this (as a string)
1 Like

I have been completely stumped with this project as well! So far with all of the projects I have done there was some sort of help if you get stumped, but this project has none at all. There is no forum to search, now follow along video, nothing. I’m really hoping that the rest of the web-app program isn’t like this. I just skipped the rest of the adopt-a-pet project. With no documentation I’m just staring at a screen with nowhere to go. I got stumped at the same point that the above person did. I’m not waiting around for an answer to float in so I’m moving along. I’m only writing this comment in hope that the Codecademy folks see that there is a problem with this project and gets one of their advanced coders to do a video.

7 Likes

For step 14, you need to assign the appropriate dictionary from within the enclosing pets dictionary to a variable named pet. Feel free to look at the helper.py file, if you would like. Use the pet function’s arguments to access the needed dictionary, as follows:

  pet = pets[pet_type][pet_id]

Try that out, then proceed to the next steps. If you encounter problems that you are unable to resolve, please post correctly formatted code for help. See How to ask good questions (and get good answers) for advice on formatting code for posting.

3 Likes

Here’s another thread on this

Same here, I have given up this project from 15 onward. It is pretty demotivating as it is the first project and there is no help. :((

2 Likes

let me know in which step were you stuck?

I also got stuck at number 12. Please help

Hi,

Your syntax error occurs on line 22, but I don’t think the screenshot shows line 22 of your code. Can you screenshot that part or share the bit of the code with the issue (</> to format)?

Thanks for the help provided in the forum.
As there is not a solution available I would like to share my code.
Seems to work
Cheers

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 bewlow 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 += f'<li><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>breed: {pet["breed"]}</li>
    <li>age: {pet["age"]}</li>
  </ul>
  '''
12 Likes

Thanks a lot! Your code helped me to solve the last task! :slight_smile:

Thanks so much for this!

This code helped me a lot! Thank you so much.

[" "] not [’ ']

nice one @datarockstar61403 , thanks for sharing.
helped to double check my code re: accessing the dictionary.
instead of return f'''{pet["name"]}''', I had incorrectly persisted with return f'''{pet['name']}'''

1 Like

Hi, I am stuck at step 12. What do I put in the for loop and why???

Hello, I am also a beginner and I have the feeling some steps are missing from step 12. Can you tell me what “enumrate” does? This is the first time I see this. I learned when you want to access keys and values you have to use .items() but I don’t get why your code doesn’t need this. When summarized, my question is: What do I have to put in the for loop and why???
Hope you can help me…

It looks like there still isn’t a video solution for this :/. Also struggling and don’t want to just throw in someone else’s code to complete the task. It also looks like this issue was brought up almost three years ago, so I guess CA isn’t going to make one…

Hey !
When I click in any animal link I get Not Found, even tho I used your code.
Am I missing something?

Solved! Two reasons for not being able to open the animal names page:
1 - I had to remove the last / in the link on the right ( not sure why )
2 - The animal names in the helpers dictionary were in lowercase , and the list I created had initial capital before each name. Example : Dogs vs dogs - so it wasn’t finding it