文件:./simple_blog/app.yaml
application: simple-blog
version: 1
runtime: python
api_version: 1
handlers:
- url: /.*
script: simple_blog.py
文件:./simple_blog/simple_blog.py
#!/usr/bin/env python # -*- coding: utf-8 -*- import cgi import sys, os import wsgiref.handlers from google.appengine.ext import webapp from google.appengine.ext.webapp import template _DEBUG = True class BaseRequestHandler(webapp.RequestHandler): """套用模板""" def render(self, template_name, template_values={}): values = { 'request': self.request, 'application_name': 'test', } values.update(template_values) directory = os.path.dirname(__file__) #指定模板文件路径 path = os.path.join(directory, os.path.join('templates', template_name)) self.response.out.write(template.render(path, values, debug=_DEBUG)) class IndexPage(BaseRequestHandler): def get(self): self.render('index.html', { 'title': 'Index', 'content': 'Hello, World' }) #配置URL路由 application = webapp.WSGIApplication([ ('/', IndexPage) ], debug=_DEBUG) def main(): wsgiref.handlers.CGIHandler().run(application) if __name__ == '__main__': main()
文件:./simple_blog/templates/index.html
{{application_name }} - {{title}} {{content}}
附件是一个完整的google app engine演示例子,关于django模板的更详细的说明请参见
http://www.woodpecker.org.cn/obp/django/django-faq/templates.html