0
0
Djangoframework~5 mins

Template variables with double braces in Django - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What do double braces {{ }} mean in Django templates?
Double braces {{ }} are used to display the value of a variable passed from the Django view to the template.
Click to reveal answer
beginner
How do you show a variable named 'username' in a Django template?
Use {{ username }} inside the template to display the value of the 'username' variable.
Click to reveal answer
intermediate
Can you use expressions inside {{ }} in Django templates?
No, Django templates only allow simple variable names or filters inside {{ }}. Complex expressions are not supported.
Click to reveal answer
beginner
What happens if a variable inside {{ }} does not exist in the context?
Django will render an empty string if the variable is missing, so nothing will show up in the output.
Click to reveal answer
intermediate
How can you modify a variable's output inside {{ }}?
You can use filters like {{ variable|lower }} to change the output, for example making text lowercase.
Click to reveal answer
What does {{ user.email }} do in a Django template?
ADisplays the email attribute of the user variable
BCalls a function named user.email
CCreates a new variable named user.email
DComments out the user.email code
If a variable inside {{ }} is missing, what will Django show?
AAn error message
BThe variable name as text
CAn empty string (nothing)
DThe word 'undefined'
Which of these is valid inside {{ }} in Django templates?
Auser.get_full_name()
Bfor item in list
Cif user.is_active
Duser.full_name|upper
How do you safely display a variable that might contain HTML in Django templates?
A{{ variable|escape }}
B{{ variable|safe }}
C{{ variable|raw }}
D{{ variable|html }}
What is the purpose of using {{ }} in Django templates?
ATo output variable values
BTo include CSS styles
CTo write comments
DTo create loops
Explain how Django template variables with double braces {{ }} work and how they connect to the view.
Think about how data moves from Python code to the HTML page.
You got /4 concepts.
    Describe how you can modify the output of a variable inside {{ }} using filters in Django templates.
    Filters are like little helpers that change how the variable looks.
    You got /4 concepts.