Using from __future__ import in Mako template
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have <%! from __future__ import division %> at the very top of my template file. I get the error: SyntaxError: from __future__ imports must occur at the beginning of the file What's the correct way to do this? 回答1: You cannot use from __future__ import statements in Mako templates. At all. This is because a Mako template is compiled to a python file, and in order for this to work it sets up some initial structures at the top of that python file: # -*- encoding:ascii -*- from mako import runtime, filters, cache UNDEFINED = runtime.UNDEFINED