0
0
Djangoframework~10 mins

URL parameters with angle brackets 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 capture an integer parameter named 'pk' in the URL pattern.

Django
path('item/[1]', views.item_detail, name='item-detail')
Drag options to blanks, or click blank then click option'
A<int:pk>/
B<str:pk>/
C<pk>/
Dpk/
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the type before the colon inside angle brackets.
Omitting the trailing slash after the parameter.
Using angle brackets without specifying type.
2fill in blank
medium

Complete the code to capture a string parameter named 'username' in the URL pattern.

Django
path('profile/[1]', views.profile_view, name='profile')
Drag options to blanks, or click blank then click option'
Ausername/
B<int:username>/
C<slug:username>/
D<str:username>/
Attempts:
3 left
💡 Hint
Common Mistakes
Using <int:username> which expects an integer, not a string.
Omitting angle brackets around the parameter.
Not including the trailing slash.
3fill in blank
hard

Fix the error in the URL pattern to correctly capture a slug parameter named 'post_slug'.

Django
path('blog/[1]', views.post_detail, name='post-detail')
Drag options to blanks, or click blank then click option'
A<slug:post_slug>/
B<str:post_slug>
C<post_slug>/
Dpost_slug/
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting the type 'slug' before the colon.
Forgetting the trailing slash.
Using angle brackets without type.
4fill in blank
hard

Fill both blanks to capture an integer 'year' and a string 'month' in the URL pattern.

Django
path('archive/[1]/[2]', views.archive_view, name='archive')
Drag options to blanks, or click blank then click option'
A<int:year>
B<str:month>
C<slug:month>
Dmonth
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'month' without angle brackets or type.
Mixing up the types for year and month.
Omitting slashes between parameters.
5fill in blank
hard

Fill all three blanks to capture a slug 'category', an integer 'id', and a string 'action' in the URL pattern.

Django
path('manage/[1]/[2]/[3]/', views.manage_view, name='manage')
Drag options to blanks, or click blank then click option'
A<slug:category>
B<int:id>
C<str:action>
Daction
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'action' without angle brackets and type.
Mixing up parameter types.
Forgetting trailing slash at the end.