jweinst1
10/1/2015 - 2:54 AM

sample function that generates a rendered HTML template from a python function

sample function that generates a rendered HTML template from a python function

def homepage(request):
    temp = Template("""<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
{{ thing }}
</body>
</html>""")
    inject = heading("How are you today?")
    html = temp.render(Context({'thing': inject}))
    return HttpResponse(html)

def heading(content):
    result = Template("<h1>" + content + "</h1>").render(Context())
    return result