Challenge - 5 Problems
Django Path Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Django URL pattern matching?
Given the following URL pattern and a request to '/blog/42/', what view will be called and what will be the value of the captured parameter?
Django
from django.urls import path from . import views urlpatterns = [ path('blog/<int:post_id>/', views.post_detail, name='post_detail'), ] # Assume views.post_detail is defined to accept post_id as argument.
Attempts:
2 left
💡 Hint
Look at how the path converter works in the URL pattern.
✗ Incorrect
The path function captures the integer part after 'blog/' and passes it as an integer argument named post_id to the view.
📝 Syntax
intermediate2:00remaining
Which option correctly defines a path with a string parameter named 'username'?
Select the correct Django path function usage to capture a string parameter 'username' from the URL '/user//'
Attempts:
2 left
💡 Hint
Remember the syntax for path converters in Django's path function.
✗ Incorrect
The correct syntax to capture a string parameter is . Omitting the converter defaults to str but is not recommended. Using int or slug changes the expected format.
🔧 Debug
advanced2:00remaining
Why does this URL pattern cause a runtime error?
Examine the following urlpatterns list and identify why it causes an error when Django starts.
Django
from django.urls import path urlpatterns = [ path('article/<int:id>/', views.article_detail), path('article/<int:id>/', views.article_edit), ]
Attempts:
2 left
💡 Hint
Check if all referenced modules are imported.
✗ Incorrect
The code references 'views.article_detail' and 'views.article_edit' without importing the 'views' module, causing a NameError when Django loads the URL configuration.
❓ state_output
advanced2:00remaining
What is the value of 'kwargs' passed to the view for this path?
Given the URL pattern and a request to '/shop/electronics/123/', what is the kwargs dictionary passed to the view?
Django
path('shop/<slug:category>/<int:item_id>/', views.item_detail, name='item_detail')
Attempts:
2 left
💡 Hint
Look at how multiple path converters capture parts of the URL.
✗ Incorrect
The slug converter captures 'electronics' as category and int converter captures 123 as item_id.
🧠 Conceptual
expert3:00remaining
Which option best explains the difference between path() and re_path() in Django routing?
Choose the most accurate explanation about the difference between path() and re_path() functions in Django URL configuration.
Attempts:
2 left
💡 Hint
Think about the syntax and flexibility differences between path and re_path.
✗ Incorrect
path() provides easy-to-read converters like , , while re_path() allows full regex for advanced patterns.