<time class="entry-date">{{% datetime.date.today().year %}}</time>
我在一个 tornado 模板中使用的 datetime 模块,如上所示!
但是运行的时候出错,错误代码如下所示:
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado-4.3.dev1-py2.7-linux-x86_64.egg/tornado/web.py", line 1411, in _execute
result = method(*self.path_args, **self.path_kwargs)
File "./blog.py", line 87, in get
self.render("index.html", aside=True, passages=passages)
File "/usr/local/lib/python2.7/dist-packages/tornado-4.3.dev1-py2.7-linux-x86_64.egg/tornado/web.py", line 701, in render
html = self.render_string(template_name, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tornado-4.3.dev1-py2.7-linux-x86_64.egg/tornado/web.py", line 805, in render_string
t = loader.load(template_name)
File "/usr/local/lib/python2.7/dist-packages/tornado-4.3.dev1-py2.7-linux-x86_64.egg/tornado/template.py", line 424, in load
self.templates[name] = self._create_template(name)
File "/usr/local/lib/python2.7/dist-packages/tornado-4.3.dev1-py2.7-linux-x86_64.egg/tornado/template.py", line 452, in _create_template
template = Template(f.read(), name=name, loader=self)
File "/usr/local/lib/python2.7/dist-packages/tornado-4.3.dev1-py2.7-linux-x86_64.egg/tornado/template.py", line 314, in __init__
"exec", dont_inherit=True)
File "index_html.generated.py", line 82
_tt_tmp = % datetime.date.today().year % # index.html:16 (via base.html:56)
^
SyntaxError: invalid syntax
我在这个网址中看到了 datetime 的使用示例,照着实例来会出问题,请问正确的方法应该如何写!
1
bwangel OP 好吧,我错了,模板语法写错了!
`<time class="entry-date">{{ datetime.date.today().year }}</time>` |