0
0
Djangoframework~10 mins

MTV pattern mental model 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 Django model class.

Django
from django.db import [1]
Drag options to blanks, or click blank then click option'
Aviews
Bmodels
Ctemplates
Dforms
Attempts:
3 left
💡 Hint
Common Mistakes
Importing views or templates instead of models.
2fill in blank
medium

Complete the code to define a Django view function.

Django
def home(request):
    return [1]('home.html')
Drag options to blanks, or click blank then click option'
Aredirect
Bmodel
Cform
Drender
Attempts:
3 left
💡 Hint
Common Mistakes
Using model or form instead of render in views.
3fill in blank
hard

Fix the error in the template tag to display a variable.

Django
<p>Hello, [1]!</p>
Drag options to blanks, or click blank then click option'
A{{ user }}
B{% user %}
Cuser
D[user]
Attempts:
3 left
💡 Hint
Common Mistakes
Adding extra braces or using template tags incorrectly.
4fill in blank
hard

Fill both blanks to create a model field for a character name with max length 100.

Django
class Person(models.Model):
    name = models.[1](max_length=[2])
Drag options to blanks, or click blank then click option'
ACharField
BIntegerField
C100
D50
Attempts:
3 left
💡 Hint
Common Mistakes
Using IntegerField for text or wrong max_length values.
5fill in blank
hard

Fill all three blanks to complete a view that queries all Person objects and renders them.

Django
from django.shortcuts import render
from .models import Person

def list_people(request):
    people = Person.objects.[1]()
    return render(request, '[2]', {'[3]': people})
Drag options to blanks, or click blank then click option'
Aall
Bpeople_list.html
Cpeople
Dfilter
Attempts:
3 left
💡 Hint
Common Mistakes
Using filter() without arguments or mismatching context keys.