本文整理汇总了Python中werkzeug.templates.Template.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python Template.from_file方法的具体用法?Python Template.from_file怎么用?Python Template.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.templates.Template
的用法示例。
在下文中一共展示了Template.from_file方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_template
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def render_template(self, template=None):
if template is None:
template = self.__class__.identifier + '.html'
context = dict(self.__dict__)
context.update(url_for=self.url_for, self=self)
body_tmpl = Template.from_file(path.join(templates, template))
layout_tmpl = Template.from_file(path.join(templates, 'layout.html'))
context['body'] = body_tmpl.render(context)
return layout_tmpl.render(context)
示例2: get_template
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def get_template(self, name):
"""Get a template from a given name."""
filename = path.join(self.search_path, *[p for p in name.split('/')
if p and p[0] != '.'])
if not path.exists(filename):
raise TemplateNotFound(name)
return Template.from_file(filename, self.encoding)
示例3: generate
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def generate(self, rsp, **kwargs):
global settings
kwargs['cfg_line'] = lambda s, d=None: s + ' = ' + repr(settings.get(s, d))
for filename in ('launch.wsgi', 'app.py', 'settings.py', 'manage.py'):
with open(in_cwd(filename), 'w') as f:
# Template strips off trailing whitespace...
f.write(Template.from_file(in_skeld(filename + '.tmpl')).render(**kwargs) + '\n')
os.chmod(in_cwd('manage.py'), 0755)
示例4: test_from_file_with_filename
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def test_from_file_with_filename():
"""Template from_file where file parameter is a filename"""
fd, filename = tempfile.mkstemp()
try:
os.write(fd, "Hello ${you}!")
finally:
os.close(fd)
try:
t = Template.from_file(filename)
assert t.render(you="World") == "Hello World!"
finally:
os.unlink(filename)
示例5: get_template
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def get_template(name):
return Template.from_file(join(dirname(__file__), 'shared', name), unicode_mode=False, errors='ignore')
示例6: get_template
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def get_template(filename):
return Template.from_file(join(dirname(__file__), 'templates', filename))
示例7: generate
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def generate(self, rsp, **kwargs):
template_data = self.req.environ.copy()
template_data.update(kwargs)
rsp.data = Template.from_file(self.filename).render(template_data)
示例8: test_from_file_with_fileobject
# 需要导入模块: from werkzeug.templates import Template [as 别名]
# 或者: from werkzeug.templates.Template import from_file [as 别名]
def test_from_file_with_fileobject():
"""Template from_file where file parameter is a file object"""
t = Template.from_file(sio.StringIO("Hello ${you}!"))
assert t.render(you="World") == "Hello World!"