Skip to content

Instantly share code, notes, and snippets.

@eliotk
Created November 19, 2011 23:49
Show Gist options
  • Save eliotk/1379554 to your computer and use it in GitHub Desktop.
Save eliotk/1379554 to your computer and use it in GitHub Desktop.
Code snippets for Django-powered layouts in Python blog post at eliotk.net
template_values = {
}
path = os.path.join(os.path.dirname(__file__), 'index.html')
self.response.out.write(template.render(path, template_values))
<html>
<head>
... css, js, meta tags ...
</head>
<body>
... main layout html perhaps including navigation and logo ...
{{view}}
</body>
</html>
class MainHandler(webapp.RequestHandler):
def get(self):
layout_values = {
'view': render_view('index.html')
}
path = os.path.join(os.path.dirname(__file__), 'layout.html')
self.response.out.write(template.render(path, layout_values))
from django.template import Template, Context
def render_view(view_name, template_dict = {}):
path = os.path.join(os.path.dirname(__file__), view_name)
f = open(path, 'r')
view_str = f.read()
t = Template(view_str)
return t.render(Context(template_dict))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment