使用 Django 模板引擎:
接下來使用一個非常簡單的範例來示範如何使用 Template,首先修改 helloworld.py 內容,
import webapp2
import os
from google.appengine.ext.webapp import template
class MainPage(webapp2.RequestHandler):
    def get(self):
        # 這邊設定要傳入頁面的參數 name,值為 Seth
        template_values = {
            'name': 'Seth'
        }
        # 指定 index.html 作為輸出的頁面
        path = os.path.join(os.path.dirname(__file__), 'index.html')
        self.response.out.write(template.render(path, template_values))
application = webapp2.WSGIApplication([
    ('/', MainPage)
], debug=True)
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <!-- {{name}} 將顯示 helloworld.py 所傳入的值 Seth -->
    <p>Hello, {{name}}!</p>
    <p>This is a template example.</p>
</body>
</html>
Environment :
・ Arch Linux
・ Python 2.7
Reference :
・ Webapp2 official site
・ Python Dev Server information
