当前位置: 首页>>代码示例>>Python>>正文


Python Template.from_file方法代码示例

本文整理汇总了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)
开发者ID:0x19,项目名称:werkzeug,代码行数:11,代码来源:application.py

示例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)
开发者ID:garyyeap,项目名称:zoe-robot,代码行数:9,代码来源:kickstart.py

示例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)
开发者ID:diazona,项目名称:Modulo,代码行数:10,代码来源:__init__.py

示例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)
开发者ID:strogo,项目名称:werkzeug,代码行数:14,代码来源:test_templates.py

示例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')
开发者ID:Pluckyduck,项目名称:eve,代码行数:4,代码来源:render.py

示例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))
开发者ID:Pluckyduck,项目名称:eve,代码行数:4,代码来源:utils.py

示例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)
开发者ID:diazona,项目名称:Modulo,代码行数:6,代码来源:minitmpl.py

示例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!"
开发者ID:strogo,项目名称:werkzeug,代码行数:6,代码来源:test_templates.py


注:本文中的werkzeug.templates.Template.from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。