Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing redirect instead of render
Using HttpResponse directly without templates
✗ Incorrect
The render function helps quickly display HTML templates with data in Django.
2fill in blank
mediumComplete 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using IntegerField for text
Using TextField without max_length
✗ Incorrect
CharField is used for short text fields like names in Django models.
3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using redirect instead of render
Returning HttpResponse without template
✗ Incorrect
The render function returns a complete webpage by combining a template and data.
4fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using url which is deprecated
Using include incorrectly here
✗ Incorrect
path is the modern way to define URL patterns in Django.
5fill in blank
hardFill 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<=' instead of '>'
Using '==' which filters only exact matches
✗ Incorrect
This comprehension keeps products with price greater than 20.