0
0
Flaskframework~10 mins

URL building with url_for 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 used for URL building in Flask.

Flask
from flask import [1]
Drag options to blanks, or click blank then click option'
Arequest
Brender_template
Curl_for
Dredirect
Attempts:
3 left
💡 Hint
Common Mistakes
Importing the wrong function like render_template instead of url_for.
Forgetting to import url_for at all.
2fill in blank
medium

Complete the code to build a URL for the 'home' route using url_for.

Flask
link = url_for('[1]')
Drag options to blanks, or click blank then click option'
Ahome
Bindex
Cmain
Ddashboard
Attempts:
3 left
💡 Hint
Common Mistakes
Using a route path like '/home' instead of the function name.
Using a different function name that does not exist.
3fill in blank
hard

Fix the error in building a URL for the 'profile' route that requires a user_id parameter.

Flask
url = url_for('profile', [1]=42)
Drag options to blanks, or click blank then click option'
Auser
Bprofile_id
Cid
Duser_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using a wrong parameter name that does not match the route.
Omitting the required parameter causing an error.
4fill in blank
hard

Fill both blanks to build a URL for the 'post' route with post_id 10 and comment_id 5.

Flask
url = url_for('[1]', post_id=[2], comment_id=5)
Drag options to blanks, or click blank then click option'
Apost
Barticle
C10
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong route name like 'article'.
Passing the post_id as a string instead of a number.
5fill in blank
hard

Fill all three blanks to build a URL for the 'edit_user' route with user_id 7 and section 'profile'.

Flask
url = url_for('[1]', [2]=[3], section='profile')
Drag options to blanks, or click blank then click option'
Aedit_user
Buser_id
C7
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'id' instead of 'user_id' for the parameter name.
Passing the user_id as a string instead of a number.