Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Well done!
You have completed A Social Network with Flask!
You have completed A Social Network with Flask!
Preview
Eventually, someone is going to type in a URL that doesn't exist, or a link is going to expire. Flask can handle these on its own, but it's nice to provide a custom error page. Let's see how to do that.
New terms
-
abort()- Function to immediately end a request with a specified status code. -
errorhandler()- Decorator that marks a function as handling a certain status code. -
return render_template('template.html'), 404- The404on the end specifies the status code for the response.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
follow and unfollow users, or viewing
user's stream, or viewing a single post.
0:00
Let's set up a view to handle these 404
errors and trigger them when we need to.
0:04
So we wanna be able to handle when a URL
is wrong.
0:09
So like for instance, this one.
0:12
Since this is generated by Flask,
0:14
we don't really have to worry about this
being wrong.
0:15
But we're putting in this post ID and it
ends up with the URL that looks like this.
0:18
And what if somebody was like, oh, they
just you know, fat-fingered it and
0:22
they wanted to go to post 15.
0:25
So it comes out like this, with nothing
there.
0:27
And that's okay, but it'd be nice if it
rendered like a 404,
0:29
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up