Challenge - 5 Problems
Django URL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What does this urlpatterns list do?
Given this Django urlpatterns list, what URL path will trigger the
home_view function?Django
from django.urls import path from .views import home_view urlpatterns = [ path('', home_view, name='home'), path('about/', lambda request: None, name='about'), ]
Attempts:
2 left
💡 Hint
Look at the first path's first argument, it defines the URL pattern.
✗ Incorrect
The empty string '' in path means the root URL. So '/' triggers home_view.
📝 Syntax
intermediate2:00remaining
Which urlpatterns list is syntactically correct?
Select the urlpatterns list that will NOT cause a syntax error in Django.
Attempts:
2 left
💡 Hint
urlpatterns must be a list, not a set or tuple.
✗ Incorrect
urlpatterns must be a list of path() calls. Option B uses a list [].
❓ state_output
advanced2:00remaining
How many URL patterns are in this urlpatterns list?
Count the number of URL patterns defined in this urlpatterns list.
Django
from django.urls import path, include urlpatterns = [ path('blog/', include('blog.urls')), path('shop/', include('shop.urls')), path('contact/', lambda request: None), ]
Attempts:
2 left
💡 Hint
Each path() call counts as one URL pattern.
✗ Incorrect
There are three path() calls, so 3 URL patterns.
🔧 Debug
advanced2:00remaining
What error does this urlpatterns list cause?
Identify the error caused by this urlpatterns list.
Django
from django.urls import path urlpatterns = [ path('home/', home_view), path('about/', about_view), path('contact/', contact_view) ]
Attempts:
2 left
💡 Hint
Check the parentheses in the last path() call.
✗ Incorrect
home_view, about_view, and contact_view are not defined, causing NameError.
🧠 Conceptual
expert3:00remaining
What is the effect of including another URLconf in urlpatterns?
In Django, what happens when you use
path('blog/', include('blog.urls')) in urlpatterns?Attempts:
2 left
💡 Hint
Think about how include() helps organize URLs.
✗ Incorrect
include() adds all URL patterns from the specified module under the given prefix.