0
0
Djangoframework~10 mins

Named URLs for maintainability in Django - Interactive Code Practice

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

Complete 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'
A'home'
B'main'
C'index'
D'start'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the name in quotes.
Using a name that is not descriptive.
2fill in blank
medium

Complete 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'
A'user_profile'
Bprofile
C'profile'
Duser_profile
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting quotes around the URL name.
Using a different name than defined in urls.py.
3fill in blank
hard

Fix 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'
A'profile'
Breverse(profile)
Cprofile
Dreverse('profile')
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the name as a plain string without reverse().
Passing the name without quotes.
4fill in blank
hard

Fill 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'
Aint
Bstr
Cpost_id
Did
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'str' instead of 'int' for numeric IDs.
Using generic names like 'id' instead of 'post_id'.
5fill in blank
hard

Fill 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'
Apost_detail
Bpost_id
C42
Dpost_pk
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.