Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Build a Social Network with Flask How to Win Friends Handling 404s

404 error

I think there is an issue with the Challenge Task 2 of 3, as it seems to want what is needed for Challenge Task 3 of 3, to continue, and then just click the check work to have it complete.

2 Answers

Hi Rune,

Unfortunately you probably didn't find Mr. Owildeberry's answer very helpful.

First a link to the challenge:

http://teamtreehouse.com/library/build-a-social-network-with-flask/how-to-win-friends/uhoh-404

Here's what I added to the bottom of lunch.py to get past part 2 of 3 for the challenge:

Challenge Task 2 of 3

Add a new function named not_found that returns the string "404". Remember, error handlers need to accept a single argument, the error. Decorate this function with @app.errorhandler(404). Add , 404 after your response, too.

@app.errorhandler(404)
def not_found(error):
    return "404", 404  

This is not the same as what is need to pass part 3 of the challenge:

Challenge Task 3 of 3

Now make not_found render the "404.html" template. Add an <h1> to the template with the 404 error code in it. Add a message to the template, if you want.

@app.errorhandler(404)
def not_found(error):
    return render_template('404.html'), 404

..which comes directly from the 'app.py' file found in the 'S4V5' folder of the course's zip download.

(Note: this is the only challenge so far where looking at the course's zip file download has been helpful to me.)

Of course you'll have to take a look at the '404.html' file under ''S4V5/templates/' folder of the course's zip,

to find the two lines needed for the {% block content %} section of the templates/404.html tab of the challenge.

Something like:

{% block content %}
<h1>404</h1>

<p>Wow, sorry, that page doesn't exist.</p>

{% endblock %}

Just wait to you get to the Tacocat challenge, though. Then you'll really be challenged!

Did you update your web browser and try a different web browser? =D