In my python Google App Engine app, the design for most of my pages is identical, so I created page.html as a basic template. The content for each individual page is in a .txt file. In my .py script I do this:
pageFile = open("content.txt", "r")
pageText = pageFile.read();
pageFile.close()
And then this
template_values = {
'full_name': full_name,
'notification': notification,
'pageText': pageText
}
path = os.path.join(os.path.dirname(__file__), 'page.html')
When the page is rendered the pageText content does get inserted, but the Django template markup (like {{full_name}}) doesn’t get parsed. Which is my problem. I suspect the solution to this is to render the html file twice, once to load in the content and once to parse the Django template stuff, but I can’t find any resources about how to do this. Any help appreciated.
EDIT: specific view code
Instruction page
class Instruction(webapp.RequestHandler):
def get(self):
checkUser(self)
checkProfile(self)
flowControl(self, 0)
prepareHeader(self)
global notification
try:
notification
except NameError:
notification = ""
pageFile = open("instruction.txt", "r")
pageText = pageFile.read();
pageFile.close()
template_values = {
'url': url,
'url_linktext': url_linktext,
'user': user,
'pageText': pageText,
'footerText': footerText,
'notification': notification
}
global instruction, refresh
instruction = True
refresh = True
path = os.path.join(os.path.dirname(__file__), 'instruction.html')
self.response.out.write(template.render(path, template_values))
You can use the Django include template tag. Or template inheritance.
This example includes the contents of the template “foo/bar.html”:
This example includes the contents of the template whose name is contained in the variable template_name: