0
0
Flaskframework~10 mins

Redirect and abort functions in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
Arender_template
Babort
Credirect
Drequest
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'abort' instead of 'redirect'.
Confusing 'render_template' with 'redirect'.
2fill in blank
medium

Complete 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'
Aabort
Bredirect
Curl_for
Dflash
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'redirect' to handle errors.
Trying to return error codes manually without 'abort'.
3fill in blank
hard

Fix 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'
Aabort
Bredirect
Crender_template
Durl_for
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'abort' instead of 'redirect'.
Using 'render_template' which only renders a page without redirecting.
4fill in blank
hard

Fill 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'
Aabort
Bredirect
C403
D404
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'redirect' instead of 'abort'.
Using the wrong error code like 404.
5fill in blank
hard

Fill 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'
Aredirect
Burl_for
Clogin
Dabort
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'abort' instead of 'redirect'.
Not using 'url_for' to build the URL.