0
0
Djangoframework~10 mins

Why URL configuration matters in Django - Test Your Understanding

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

Complete the code to import the function needed to define URL patterns in Django.

Django
from django.urls import [1]
Drag options to blanks, or click blank then click option'
Arender
Bpath
CHttpResponse
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'render' instead of 'path'
Using 'HttpResponse' in URL config
2fill in blank
medium

Complete the code to define a URL pattern that connects the root URL to the home view.

Django
urlpatterns = [
    [1]('', home, name='home'),
]
Drag options to blanks, or click blank then click option'
Ainclude
Burl
Cpath
Droute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'include' instead of 'path'
Using 'url' which is deprecated in Django 2+
3fill in blank
hard

Fix the error in the URL pattern by completing the missing part to import views correctly.

Django
from . import [1]

urlpatterns = [
    path('', [1].home, name='home'),
]
Drag options to blanks, or click blank then click option'
Aviews
Burls
Cmodels
Dtemplates
Attempts:
3 left
💡 Hint
Common Mistakes
Importing 'urls' instead of 'views'
Importing 'models' which is for data
4fill in blank
hard

Fill both blanks to include another app's URLs under the 'blog/' path.

Django
urlpatterns = [
    path('blog/', [1]('[2].urls')),
]
Drag options to blanks, or click blank then click option'
Ainclude
Bblog
Cviews
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'path' instead of 'include'
Using 'views' instead of app name
5fill in blank
hard

Fill all three blanks to create a URL pattern that captures an integer 'post_id' and calls the 'post_detail' view.

Django
urlpatterns = [
    path('[1]/<[2]:post_id>/', [3].post_detail, name='post_detail'),
]
Drag options to blanks, or click blank then click option'
Ablog
Bint
Cviews
Dstr
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'str' instead of 'int' for the parameter type
Using wrong module name for views