0
0
Djangoframework~20 mins

Template variables with double braces in Django - Mini Project: Build & Apply

Choose your learning style9 modes available
Template variables with double braces
📖 Scenario: You are building a simple Django web page to show a user's profile information. The data will come from the backend and be displayed in the HTML template.
🎯 Goal: Create a Django template that uses double braces {{ }} to show the user's name and age on the page.
📋 What You'll Learn
Create a dictionary called user with keys 'name' and 'age' and exact values 'Alice' and 30
Create a variable called title with the value 'User Profile'
Use double braces {{ }} in the template to display title in an <h1> tag
Use double braces {{ }} in the template to display user.name and user.age inside <p> tags
💡 Why This Matters
🌍 Real World
Django templates use double braces {{ }} to safely insert data from the backend into HTML pages, making dynamic websites.
💼 Career
Understanding Django template variables is essential for backend web developers working with Python and Django to build interactive web pages.
Progress0 / 4 steps
1
Create the user data dictionary
Create a dictionary called user with these exact entries: 'name': 'Alice' and 'age': 30.
Django
Need a hint?

Use curly braces {} to create a dictionary with keys and values.

2
Add a title variable
Create a variable called title and set it to the string 'User Profile'.
Django
Need a hint?

Use an equals sign = to assign the string to the variable.

3
Write the HTML template with title
Write an HTML template string called template that includes an <h1> tag showing the variable title using double braces {{ title }}.
Django
Need a hint?

Use triple quotes ''' to create a multi-line string for the template.

4
Add user details to the template
Extend the template string to include two <p> tags that show user.name and user.age using double braces: {{ user.name }} and {{ user.age }}.
Django
Need a hint?

Use double braces {{ }} to insert variables inside the HTML tags.