Flask Pet Lesson

Hi, I need help with step twelve of the Pet Flask Lesson.
The text is extremely bad written, causing a lot of confusion among students. I need help understanding exactly what is wrong with my code, regarding only the steps from 1 to 12. There are other topics about this, but It includes further code from the lesson.

Here is the link:
[https://www.codecademy.com/paths/build-python-web-apps-flask/tracks/introduction-to-flask/modules/introduction-to-flask/projects/adopt-a-pet]

Here is my code:

from flask import Flask
from helper import pets

app = Flask(__name__)

@app.route('/index')
@app.route('/')
def index():
  return f'''
  <h1> Adopt a Pet! </h1>
  <p>Browse through the links below to find your new furry friend:</>
  <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/')
app.route('/animals/pet_type')
def animals(pet_type):
  html = '<h1>List of {pet_type}</h1>'
  html += '<ul>'

  for pet_type, name in pets:
    html += '''
     <li>
    {pet_type}
     </li>'''
  html += '</ul>'
  return html

Hi,

Let’s think about this:

  • What are the particular issues you’re find with your code?
  • What are the attempts at debugging that you’ve tried?
  • Have you tried running this locally with FLASK DEBUG enabled, what kind of error messages do you get?

Moreover, as a general piece of advice, I just find that the narrow column structure of these longer projects is not conducive to good visualization and planning (especially as they get harder and longer… 50+ steps). Have you tried working out in pseudocode what the instructions are trying to aim at?

1 Like

Sir, thank you very much for your reply.

I am a beginner.

This project is the first one in the Flask Beginner Course, so I have not done what you said because I am still learning the very basics.

As I said, I think I understood what step 12 is asking me to do (confusing text), but I do not get the expected result, reason why I am asking for help.

Hi,

So what the text is asking you to do is to basically convert the information you have into an html string. You can practice this in regular python to see if what you’re doing works.

  • create a dictionary of information
  • iterate over it to create your desired formatting (in this case html)
  • print out the html and you can copy and paste it into an html doc to test it yourself
  • bonus points (you can make the file executable and redirect the output to an empty html file in the command-line).

Once you’re sure you have this idea clean, you can add it to your program.

For reference, you can go over the python modules of dictionaries and for-loops to get more practice.

5 Likes

Is there anyone else who can actually help me here? I don’t have the knowledge to inspect as previously stated, so if my question can be answered by someone from de CC team it would be really nice. That way, I can learn with the example of the FIRST project I am doing with Flask,

@toastedpitabread has done a great job of actually helping you. If you are not sure on the Python basics needed for this course then I recommend completing that course first.

4 Likes

The issues lie with your routing, and the way you are attempting to access the data with your for loop.

If you go back over how to create a route with variables, you will see pretty quickly why this code doesn’t work:

So the first step is to re-define your route decorators as described in that exercise.


As far as your animals function, I think it’s fair to say the Codecademy material doesn’t make this particularly intuitive, so let me do my best to explain.

When you define your route function like this

def animals(pet_type):
    ...

you need to understand where the pet_type argument will be coming from.

In this example, pet_type is literally whatever comes after/animals/ in the URL.
So, if you navigate to localhost/animals/sloth, the string "sloth" will be passed in as the pet_type for the animals() function.

In your earlier code, we can see that there are 3 different urls that we will be trying to access through that route: dogs, cats and rabbits

That means the function calls to animals() will look like this, depending on which URL you visit:
animals("dogs"),
animals("cats"), OR
animals("rabbits")

Knowing that, you need to decide how to access the data in the pets dictionary using the pet_type that was passed into the animals function.

The instructions in part 12 say this:

… create a for loop that iterates over each element in the list of pets. You can access the appropriate list of pets in the pets dictionary by the key, pet_type . Inside the loop, create a <li> element for each pet’s name and concatenate the string to html.

This is admittedly somewhat confusing, so let’s break it down.
The pets dictionary is structured like this:

pets = {
    'dogs': [
        {
            'name': 'Spot',
             ...
        },
        {
            'name': 'Shadow',
             ...
        }
    ],
    'cats': [
        {
            ...
        }
    ]
}

For each url, we want to grab the appropriate list of data from this dictionary.
The dictionary key for that list is the same string that is being passed as pet_type to arguments(). So the “appropriate list of pets” is located at pets[pet_type].

Now that you’ve got that list, the instructions want you to loop through each pet in that list and create a <li> element with that pet’s name.

Hopefully this helps clear some of the confusion. Happy coding.

3 Likes

Thank you so much for your empathy and help.

You really understood what I was asking for, recognized the flaws in the codecademy lesson and provide me clear guidance.

Considering this is a paid service, I was expecting this from the start.

SHAME ON the codecademy staff and moderator for letting this pass without doing what you just did and still condemn me, on a private message, for humbly ask for help, even though a lot of people posted about this specific confusing item and lack of walk-through video solution for this.

When someone ask for help, one should not send the person to the library or generic say to attend a “python course”, without even trying to understand what is being asked for and what the confusion is all about. I have never seen this kind of feedback, not even for more simple questions on stack overflow. This is a school, not a court.

Again, thank you very much :pray::raised_hands:

@system9234867148,

I’m glad I was able to help shed some of your confusion.

However, I’d like to ask you to please not take any of your frustration out on @toastedpitabread or @alexc.

All of us Moderators and Super Users are volunteers. We put in a lot of our time (sometimes many hours a day) to help fellow learners here in the forums and we do so out of the kindness of our hearts. We don’t get paid a single dollar for our efforts.

That said, even though we try to help, sometimes our answers don’t resonate with a learner as well as someone else’s answer. Everyone learns in different ways and what helps the material “click” for one learner might make no sense to another learner.

So please, if you feel something in the lessons and projects does not make sense even after going back to review the previous lessons, feel free to bring it up with Codecademy directly by filing a bug report about the content. But do not take it out on the volunteers here in the forums.

We do our best to help, but we are human too.

9 Likes

Thanks to all who tried to help, but, let’s be clear, I am not blaming a specific person, or “frustrated towards specific users” as previously stated, so let’s bring light to the issue:

Since the beginning of the topic, I was just kindly asking for what Codecademy have promised when I paid for a subscription: help. I legitimately expected professional help from the official staff here in the forums. If there is none, that should be mentioned somewhere before the subscription/learning contract was concluded.

Therefore, when I ask for help - or every other person here asks for help -, I am always talking to the CC institution and what has been contractually promised, not the person behind each username.

It is, in fact, a surprise to know that you are not paid. But, even though many (all?) are volunteers, there are some guidelines that should be considered when some question is asked (being a volunteer or not), and one should really consider what is behind the student doubt (like you did and recognized on your wonderfully humane-empathetic-reply).

For instance, I am a volunteer to help people learn math and essays. I do not ask a beginner to just read a book about the subject: I need to understand the question to properly help them understand the basics and, then, with time, provide guidance for further self-improvement. That is the obvious mindset behind every teacher’s work, be it voluntary or not.

Send a person for a “python course” is not helpful at all and being voluntary does not validate this action; Put shame on who is asking something is also definitely not helpful and is extremely harmful to a safe learning environment, even more considering that 1) It is the first flask project; 2) the question is about a lesson item that is not clear and is the reason for many other user posts, as we can see here in the forums.

In sum, I really have difficulty understanding why this - a feature the website advertise/promise - is being taken personally. I hope this talk helps CC to better establish guidelines to help people out when they need it and also to have some properly paid staff to help people out in the forums.

Also, there should be guidelines to solve a person’s issue without creating further embarrassment by making this extremely personal with messages like the one before this.

Many might feel ashamed by the kind of answer I got, demotivated to continue learning, and detached from the CC platform.

And, to end this, I appreciate your feedback. I also reported a bug (with no answer) and also asked a moderator to further help me out in this matter, before writing a reply to this post, but none of this worked and, again, things got out of control by personal feelings.

This is about CC, not you guys who are helping here. All my respect to every person here.

I wish you all a great day.

Hello!

My name is Alyssa, a member of the Codecademy team. I’ve read this thread in full, and will DM you to ask you for more details about any interactions that happened via DM that will provide more context.

I’d like to understand more of the friction you’ve experienced before taking full action, but some things I can do in the mean time:

  • Share with our curriculum team your feedback on the Flask lessons
  • Share that you (like many others) are seeking assistance from a Codecademy staff member

I will also reiterate a point that a number of volunteer super users (SU) and moderators made: they are volunteers— and excellent ones at that! They are providing assistance because teaching is a form of learning. They have the Codecademy team’s full support to be present and help in a way that is enriching to their own learning experience, but are not obligated in any way. If there’s ever an issue receiving support from an SU or mod, chances are it’s a matter of setting expectations, and I am happy to be contacted to help.

Please also consider this message an invitation to DM me anytime while you’re learning with Codecademy. The volunteers are here to support, but any item your feedback you have about Codecademy can come straight to me or our support team at help.codecademy.com.

11 Likes