0
0
Flaskframework~5 mins

Custom error pages (404, 500) in Flask - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the purpose of a custom 404 error page in a Flask app?
A custom 404 error page shows a friendly message when a user tries to visit a page that does not exist. It improves user experience by guiding them back to valid pages instead of showing a generic error.
Click to reveal answer
beginner
How do you define a custom error handler for a 500 Internal Server Error in Flask?
Use the @app.errorhandler(500) decorator on a function that returns a response or template. This function runs when a server error happens, letting you show a custom message or page.
Click to reveal answer
beginner
Which Flask function is used to render a custom error page template?
The render_template() function is used to load and show an HTML template for the error page, allowing you to design a nice layout and message.
Click to reveal answer
intermediate
Why is it important to return the correct HTTP status code with a custom error page?
Returning the correct status code (like 404 or 500) helps browsers and search engines understand the error type. It also helps tools and users know the page is an error, not a normal page.
Click to reveal answer
beginner
What happens if you don't define a custom error handler for 404 in Flask?
Flask shows a default plain text 404 error page. It works but looks basic and may confuse users. Custom pages improve clarity and keep your site style consistent.
Click to reveal answer
Which decorator is used to create a custom 404 error page in Flask?
A@app.errorhandler(404)
B@app.route('/404')
C@app.handle_error(404)
D@app.custom_error(404)
What should a custom error handler function return?
AA rendered template and the error status code
BOnly a string message
CNothing, just print an error
DRedirect to homepage
What HTTP status code is used for Internal Server Error?
A404
B500
C403
D200
If you want to show a custom page for any error, which decorator can you use?
A@app.route('/error')
B@app.errorhandler(404)
C@app.errorhandler(Exception)
D@app.catch_all()
Why should custom error pages be user-friendly?
ATo confuse users
BTo hide errors completely
CTo slow down the website
DTo help users understand what went wrong and guide them
Explain how to create a custom 404 error page in Flask and why it is useful.
Think about how Flask handles errors and how you can show a nicer page.
You got /4 concepts.
    Describe the difference between default Flask error pages and custom error pages.
    Consider what users see and how it affects their experience.
    You got /4 concepts.