Google App EngineではDjangoを利用することができる。
テンプレートを使う時はテンプレートフォルダを作って、そこにHTMLのひな形ファイルを作成して使用する。
ファイル構成例
tmpl/hello.html
app.yaml
main.py
但し、一つ注意するのが、テンプレートファイルは静的ファイル扱いではなくスクリプトファイル扱いとなるので、app.yamlに
テンプレートを使う時はテンプレートフォルダを作って、そこにHTMLのひな形ファイルを作成して使用する。
ファイル構成例
tmpl/hello.html
app.yaml
main.py
class TestHandler(webapp.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'application/xhtml+xml; charset=Shift_JIS'
template_values = {
'app_id': "test",
'user_info': "userinfo",
}
path = os.path.join(os.path.dirname(__file__), 'tmpl/hello.html')
self.response.out.write(template.render(path, template_values)) 但し、一つ注意するのが、テンプレートファイルは静的ファイル扱いではなくスクリプトファイル扱いとなるので、app.yamlに
- url: /tmpl
static_dir: tmpl
ではなくて static_dir: tmpl
- url: /tmpl
script: tmpl/(.html)
script: tmpl/(.html)
とする。
そうしないとTemplateDoesNotExist: hello.htmlというエラーが出る。
0 件のコメント:
コメントを投稿