0
0
Djangoframework~10 mins

path function for routes 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 import the path function from Django.

Django
from django.urls import [1]
Drag options to blanks, or click blank then click option'
Apath
Broute
Curl
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'url' instead of 'path' which is deprecated in newer Django versions.
Trying to import 'route' which does not exist.
2fill in blank
medium

Complete the code to define a URL pattern for the home page using the path function.

Django
urlpatterns = [
    [1]('', views.home, name='home'),
]
Drag options to blanks, or click blank then click option'
Aurl
Bpath
Croute
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'url' which is deprecated.
Using 'include' which is for including other URL configs.
3fill in blank
hard

Fix the error in the URL pattern by completing the path function call correctly.

Django
urlpatterns = [
    path('blog/[1]', views.blog_post, name='blog_post'),
]
Drag options to blanks, or click blank then click option'
A<int:id>
B<str:post_id>
C<int:post_id>
D<slug:post_id>
Attempts:
3 left
💡 Hint
Common Mistakes
Using when the view expects post_id.
Using when the parameter should be an integer.
4fill in blank
hard

Fill both blanks to create a URL pattern that includes another URL configuration.

Django
urlpatterns = [
    [1]('blog/', [2]('blog.urls')),
]
Drag options to blanks, or click blank then click option'
Apath
Binclude
Curl
Droute
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'url' instead of 'path'.
Using 'path' for both blanks.
5fill in blank
hard

Fill all three blanks to create a URL pattern with a slug parameter and a name.

Django
urlpatterns = [
    [1]('article/[2]', views.article_detail, name=[3]),
]
Drag options to blanks, or click blank then click option'
Apath
B<slug:slug>
C'article_detail'
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using instead of .
Not quoting the name string.