Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to import the function that sends users to a different page.
Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'abort' instead of 'redirect'.
Confusing 'render_template' with 'redirect'.
✗ Incorrect
The redirect function is used to send users to a different URL in Flask.
2fill in blank
mediumComplete the code to stop the request and return a 404 error.
Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'redirect' to handle errors.
Trying to return error codes manually without 'abort'.
✗ Incorrect
The abort function stops the request and returns an HTTP error code like 404.
3fill in blank
hardFix the error in this code that tries to redirect to the home page.
Flask
return [1]('/')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'abort' instead of 'redirect'.
Using 'render_template' which only renders a page without redirecting.
✗ Incorrect
The redirect function is used to send the user to a different URL, like the home page.
4fill in blank
hardFill both blanks to abort with a 403 Forbidden error and a custom message.
Flask
return [1]([2], description='Access denied')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'redirect' instead of 'abort'.
Using the wrong error code like 404.
✗ Incorrect
Use abort with the error code 403 to stop the request and show 'Forbidden'.
5fill in blank
hardFill all three blanks to redirect to the 'login' page using url_for inside redirect.
Flask
return [1]([2]('[3]'))
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'abort' instead of 'redirect'.
Not using 'url_for' to build the URL.
✗ Incorrect
Use redirect with url_for to send users to the 'login' page.