settings.configure()
template = """
<html>
<head>
<title>Template {{ title }}</title>
</head>
<body>
Body with {{ mystring }}.
</body>
</html>
"""
t = Template(template)
c = Context({'title': 'title from code', 'mystring': 'string from code'})
print(t.render(c))
Generating HTML documents in python