2012-05-30 38 views
2

我想在谷歌應用程序引擎jinja2中使用繼承。但迄今爲止我還沒有做到這一點。你能指點我做錯了什麼嗎?Jinja2繼承將無法運行

這裏是我的base.html

{{text}} 
{% block title %} 
Failure 
{% endblock %} 

這個模板由title.html擴展:

{% extends "base.html" %} 
{% block title %} 
World!! 
{% endblock %} 

兩個模板都在同一個目錄/templates/wiki

我這是怎麼加載模板和渲染base.html

import os 
import jinja2 
import webapp2 

template_dir = os.path.join(os.path.dirname(__file__), '../templates/wiki') 
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True) 

class MyHandler(webapp2.RequestHandler): 
def get(self): 
    templ = jinja_env.get_template('base.html') 
    self.response.out.write(templ.render(text = 'Hello,')) 

假想的輸出

你好,世界!

,但我可以得到的只是:

你好,故障

Jinja2的版本是2.6。

+0

您是否總是加載'base.html'模板(tmpl = jinja_env.get_template('base.html)? – Nicoretti

+0

@Nicoretti我不知道我是否正確理解您的問題。 –

回答

4

您必須呈現title.html而不是base.html。

+0

謝謝!:) –