Master pages for GAE project (python)
I've got a project running on GAE and I am quite sick of manual support 开发者_JS百科of headers and footers in all the page templates I have. Is there any way to use master pages for GAE?
You can have a _base.htm
template with header and footer:
<!-- header -->
{% block bodycontent %}
{% endblock %}
<!-- footer -->
And expand it using specific templates:
{% extends "_base.htm" %}
{% block bodycontent %}
<!-- template-specific stuff -->
{% endblock %}
Example
This is a template folder of my cms-app on github:
templates/
├── _404.htm
├── _base.htm
├── _edit.htm
├── _login.htm
├── _unavailable.htm
├── blog.htm
└── default.htm
Where blog.htm and default.htm templates extend the _base.htm template with headers, footers and counters.
Side note,
On my other app, which is not on github, I use naming convention with names like search.foo.base.htm
which means that it's a templates that extends foo.base.htm
template, which extends base.htm
template - I think this is a useful tip if you have complex hierarchy of templates.
Documentation
GAE uses django templates version 0.96 (by default), which docs could not be found on djangoproject.com site. However, some good people put them online, see this question: Missing Django 0.96 Template documentation (used by Google AppEngine developers)
精彩评论