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?
✗ Incorrect
The @app.errorhandler(404) decorator tells Flask to use the decorated function when a 404 error occurs.
What should a custom error handler function return?
✗ Incorrect
The function should return a rendered template (HTML) and the correct HTTP status code to properly show the error page.
What HTTP status code is used for Internal Server Error?
✗ Incorrect
500 is the standard HTTP status code for Internal Server Error.
If you want to show a custom page for any error, which decorator can you use?
✗ Incorrect
Using @app.errorhandler(Exception) catches all exceptions and can be used to show a generic error page.
Why should custom error pages be user-friendly?
✗ Incorrect
User-friendly error pages help users know what happened and how to continue, improving their experience.
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.