0
0
Djangoframework~10 mins

How Django processes a request (URL → View → Template) - Interactive Practice

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

Complete the code to define a URL pattern that connects the path 'home/' to the view function.

Django
urlpatterns = [path('home/', [1])]
Drag options to blanks, or click blank then click option'
Arender
Bhome_view
CHttpResponse
Dinclude
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'render' or 'HttpResponse' directly in the URL pattern instead of a view function.
Using 'include' which is for including other URL configurations.
2fill in blank
medium

Complete the view function to render the 'home.html' template with the request.

Django
def home_view(request):
    return [1](request, 'home.html')
Drag options to blanks, or click blank then click option'
Arender
BHttpResponse
Credirect
Dget_object_or_404
Attempts:
3 left
💡 Hint
Common Mistakes
Using HttpResponse directly without rendering a template.
Using redirect which sends a new URL instead of rendering a template.
3fill in blank
hard

Fix the error in the view function to correctly pass context data to the template.

Django
def home_view(request):
    context = {'message': 'Hello!'}
    return render(request, 'home.html', [1])
Drag options to blanks, or click blank then click option'
Acontext
Brequest
C'message'
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the request object again instead of context.
Passing a string key instead of the whole context dictionary.
4fill in blank
hard

Fill both blanks to complete the URL pattern that includes another app's URLs and names the route 'blog-home'.

Django
urlpatterns = [path('blog/', [1]('blog.urls'), name=[2])]
Drag options to blanks, or click blank then click option'
Ainclude
B'blog-home'
C'blog_home'
Dpath
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'path' instead of 'include' to include URLs.
Using an invalid name format or missing quotes.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each word to its length if the length is greater than 3.

Django
lengths = { [1]: [2] for [3] in words if len([3]) > 3 }
Drag options to blanks, or click blank then click option'
Aword
Blen(word)
Ditem
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not filtering words by length.