December 2018
Beginner to intermediate
796 pages
19h 54m
English
Each template gets a set of context variables. Like Python's string format() method's single curly brace {variable} syntax, Django uses the double curly brace {{ variable }} syntax. Let's see how they compare:
In pure Python, the syntax is <h1>{title}</h1>. For example:
>>> "<h1>{title}</h1>".format(title="SuperBook")
'<h1>SuperBook</h1>'
The syntax equivalent in a Django template is <h1>{{ title }}</h1>. Rendering with the same context will produce the same output as follows:
>>> from django.template import Template, Context
>>> Template("<h1>{{ title }}</h1>").render(Context({"title": "SuperBook"}))
'<h1>SuperBook</h1>'
Read now
Unlock full access