Created
November 19, 2011 23:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template_values = { | |
} | |
path = os.path.join(os.path.dirname(__file__), 'index.html') | |
self.response.out.write(template.render(path, template_values)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
... css, js, meta tags ... | |
</head> | |
<body> | |
... main layout html perhaps including navigation and logo ... | |
{{view}} | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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