As in Python programming language, for statement in Jinja2 template language is to iterate over a variable that is a container object.

 

#home/views.py
from django.shortcuts import render

# Create your views here.
def index(request):
    kdict = {
        'siteTitle':'Khmer Web',
        'pageTitle': 'Home',
        'message': '<b>ស្វាគមន៍​មក​កាន់​ទំព័រ​ដើម!</b>'
    }
    
    return render(request,'base.html',context={'data':kdict})

 

<!--home/templates/base.html-->
{% load static %}
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8"/>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
        <title>{{ data.siteTitle }} | {{ data.pageTitle }}</title> 
        <link rel="stylesheet" href="{% static 'styles/base.css' %}" />
        <link rel="stylesheet" href="{% static 'fonts/setup.css' %}" />
        <link rel="icon" href="{% static 'images/siteLogo.png' %}" />
    </head>
    <body>
        <p>
        {% for key,value in data.items %}
            <p>{{ value|safe }}</p>
        {% endfor %}
        </p>
    </body>
</html>

 

GitHub: https://github.com/Sokhavuth/khmerweb-django

Heroku: https://khmerweb-django.herokuapp.com