0
0
Djangoframework~10 mins

Why Django for rapid web development - 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 Django shortcut for rendering templates.

Django
from django.shortcuts import [1]
Drag options to blanks, or click blank then click option'
Arender
Bredirect
CHttpResponse
Dget_object_or_404
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing redirect instead of render
Using HttpResponse directly without templates
2fill in blank
medium

Complete the code to define a simple Django model with a name field.

Django
class Product(models.Model):
    name = models.[1](max_length=100)
Drag options to blanks, or click blank then click option'
AIntegerField
BCharField
CTextField
DDateField
Attempts:
3 left
💡 Hint
Common Mistakes
Using IntegerField for text
Using TextField without max_length
3fill in blank
hard

Fix the error in the view function to return a rendered template.

Django
def home(request):
    return [1](request, 'home.html')
Drag options to blanks, or click blank then click option'
Aredirect
Bget_object_or_404
Crender
DHttpResponse
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect instead of render
Returning HttpResponse without template
4fill in blank
hard

Fill both blanks to create a URL pattern for the home view.

Django
from django.urls import [1]

urlpatterns = [
    [2]('home/', views.home, name='home'),
]
Drag options to blanks, or click blank then click option'
Apath
Burl
Cinclude
Dre_path
Attempts:
3 left
💡 Hint
Common Mistakes
Using url which is deprecated
Using include incorrectly here
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension filtering products by price.

Django
filtered = {product.name: product.price for product in products if product.price [1] [2]

# Only include products with price [3] 20
Drag options to blanks, or click blank then click option'
A>
B20
C<=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>'
Using '==' which filters only exact matches