FAQ: Build Your First Flask App - Review

This community-built FAQ covers the “Review” exercise from the lesson “Build Your First Flask App”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Build Python Web Apps with Flask

FAQs on the exercise Review

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in #get-help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to #get-help and #community:tips-and-resources. If you are wanting feedback or inspiration for a project, check out #project.

Looking for motivation to keep learning? Join our wider discussions in #community

Learn more about how to use this guide.

Found a bug? Report it online, or post in #community:Codecademy-Bug-Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

I had issues with using the various links that we were asked to use in the project. For the last problem I could only get my project to work if I used http://localhost:5000/article/my-first-flask-app instead of the http://127.0.0.1:5000/article/my-first-flask-app . I understand 127.0.0.1 is the same thing as localhost but maybe it’s an issue with my os(manjaro)?

1 Like

Hello, I have a problem with my Project.
can you help me. I am stuck on #16 task:

from helper import pets
from flask import Flask

app = Flask(__name__)

@app.route('/')
@app.route('/index')
def index():
  return """
  <h1>Adopt a Pet!</h1>
  <p>Browse through the links below to find your new furry friend:</p>
  <ul>
    <a href="/animals/dogs"><li>Dogs</li>
    <a href="/animals/cats"><li>Cats</li>
    <a href="/animals/rabbits"><li>Rabbits</li>
  </ul>
  """
@app.route('/animals/<path:pet_type>')
def animals(pet_type):
  listPets = """<ul>
  """
  for idx, item in enumerate(pets[pet_type]):
    listPets += '<li><a href="">' + item + '</a></li>'
  listPets += "</ul>"
  return f'''
    <a href="/"><h1>List of {pet_type}</h1></a>
    ''' + listPets

@app.route('/animals/<path:pet_type>/<int:pet_id>')
def pet(pet_type, pet_id):
  pet = pets[pet_type][pet_id]
  return f'''
  <h1>{pet}</h1>
  <a href="/">Return to home page</a>
  '''.format(pet[pet_id])

Where I am wrong?

What is the exercise asking you to do. If I were to guess from this it’s to show the different types of formatted strings you can return.

I think this seems redundant here (both an f-string and a formatted string). It doesn’t throw an error but if the exercise is about this they may not like it.

return f'''
  <h1>{pet}</h1>
  <a href="/">Return to home page</a>
  '''.format(pet[pet_id])

Here is an example to highlight what I’m trying to say:

pet = "dog"

print(f"{pet}")
# 'dog'

print("{}".format(pet))
# 'dog'

print(f"{pet}".format(pet))
# 'dog'
1 Like

This can Help You…!