请教jinja2的问题

2012-10-16 00:39:48 +08:00
 gino
def render_template(filename, **context):
extensions = context.pop('extensions', [])
globals = context.pop('globals', {})

jinja_env = Environment(
loader = FileSystemLoader([os.path.join(os.path.dirname(__file__), 'templates'),'templates']),
extensions = extensions,
bytecode_cache = FileSystemBytecodeCache('/tmp', '%s.jinja2'),
cache_size = 50,
encoding = 'utf-8',
autoescape = False,
finalize = None,
optimized = True,
auto_reload = True, #None
)
jinja_env.globals.update(globals)
return jinja_env.get_template(filename).render(context)


----
def get(self):
self.render_template('testjinja2.html',name='google')


-----
总是错误
self.render_template('testjinja2.html',name='google')
TypeError: render_template() takes exactly 1 argument (3 given)
4476 次点击
所在节点    Python
2 条回复
linnchord
2012-10-16 01:14:26 +08:00
self.render_template

这个self是从哪儿来的?

要么定义
def render_template(self, filename, **context):

要么调用的时候不要通过self调用

这是一个python函数使用问题,和jinja没有关系。
gino
2012-10-16 08:34:28 +08:00
def render_template(self, filename, **context):

我添加了self后,输出变成空白了

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/50070

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX