Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to name the URL pattern for the home page.
Django
path('', views.home, name=[1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the name in quotes.
Using a name that is not descriptive.
✗ Incorrect
Naming the URL pattern 'home' helps refer to it easily in templates and views.
2fill in blank
mediumComplete the code to reverse the named URL 'profile' in a Django template.
Django
{% url [1] %} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the URL name.
Using a different name than defined in urls.py.
✗ Incorrect
In Django templates, the URL name must be a quoted string inside the {% url %} tag.
3fill in blank
hardFix the error in this view code that tries to redirect using a named URL.
Django
return redirect([1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the name as a plain string without reverse().
Passing the name without quotes.
✗ Incorrect
The redirect function needs a URL string, so use reverse() to get the URL from the name.
4fill in blank
hardFill both blanks to define a named URL pattern with a dynamic integer parameter 'post_id'.
Django
path('post/<[1]:[2]>/', views.post_detail, name='post_detail')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'str' instead of 'int' for numeric IDs.
Using generic names like 'id' instead of 'post_id'.
✗ Incorrect
The URL converter 'int' captures an integer, and 'post_id' is the parameter name used in the view.
5fill in blank
hardFill all three blanks to reverse a named URL 'post_detail' with a dynamic 'post_id' parameter in a view.
Django
url = reverse('[1]', kwargs={{'[2]': [3])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong parameter name in kwargs.
Not quoting the URL name.
Passing a variable instead of a value for the parameter.
✗ Incorrect
reverse() needs the URL name, the parameter name as a key in kwargs, and the actual value to fill in.