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


Python template.Loader方法代码示例

本文整理汇总了Python中tornado.template.Loader方法的典型用法代码示例。如果您正苦于以下问题:Python template.Loader方法的具体用法?Python template.Loader怎么用?Python template.Loader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.template的用法示例。


在下文中一共展示了template.Loader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_template_loader

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def create_template_loader(self, template_path):
        """返回给定路径的新模板装载器.

        可以被子类复写. 默认返回一个在给定路径上基于目录的装载器,
        使用应用程序的 ``autoescape`` 和 ``template_whitespace``
        设置. 如果应用设置中提供了一个 ``template_loader`` ,
        则使用它来替代.
        """
        settings = self.application.settings
        if "template_loader" in settings:
            return settings["template_loader"]
        kwargs = {}
        if "autoescape" in settings:
            # autoescape=None means "no escaping", so we have to be sure
            # to only pass this kwarg if the user asked for it.
            kwargs["autoescape"] = settings["autoescape"]
        if "template_whitespace" in settings:
            kwargs["whitespace"] = settings["template_whitespace"]
        return template.Loader(template_path, **kwargs) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:21,代码来源:web.py

示例2: create_template_loader

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def create_template_loader(self, template_path: str) -> template.BaseLoader:
        """Returns a new template loader for the given path.

        May be overridden by subclasses.  By default returns a
        directory-based loader on the given path, using the
        ``autoescape`` and ``template_whitespace`` application
        settings.  If a ``template_loader`` application setting is
        supplied, uses that instead.
        """
        settings = self.application.settings
        if "template_loader" in settings:
            return settings["template_loader"]
        kwargs = {}
        if "autoescape" in settings:
            # autoescape=None means "no escaping", so we have to be sure
            # to only pass this kwarg if the user asked for it.
            kwargs["autoescape"] = settings["autoescape"]
        if "template_whitespace" in settings:
            kwargs["whitespace"] = settings["template_whitespace"]
        return template.Loader(template_path, **kwargs) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:22,代码来源:web.py

示例3: render_string

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def render_string(template_name, **kw):
                template_path = self.get_template_path()
                if not template_path:
                    frame = sys._getframe(0)
                    web_file = frame.f_code.co_filename
                    while frame.f_code.co_filename == web_file:
                        frame = frame.f_back
                    template_path = os.path.dirname(frame.f_code.co_filename)
                with RequestHandler._template_loader_lock:
                    settings = self.application.settings
                    kwarg = {}

                    if "autoescape" in settings:
                        kwarg["autoescape"] = settings["autoescape"]
                    loader = template.Loader(template_path, **kwarg)
                t = loader.load(template_name)
                namespace = self.get_template_namespace()
                namespace.update(kw)
                return t.generate(**namespace) 
开发者ID:mqingyn,项目名称:torngas,代码行数:21,代码来源:exception.py

示例4: create_template_loader

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def create_template_loader(self, template_path):
        """Returns a new template loader for the given path.

        May be overridden by subclasses.  By default returns a
        directory-based loader on the given path, using the
        ``autoescape`` application setting.  If a ``template_loader``
        application setting is supplied, uses that instead.
        """
        settings = self.application.settings
        if "template_loader" in settings:
            return settings["template_loader"]
        kwargs = {}
        if "autoescape" in settings:
            # autoescape=None means "no escaping", so we have to be sure
            # to only pass this kwarg if the user asked for it.
            kwargs["autoescape"] = settings["autoescape"]
        return template.Loader(template_path, **kwargs) 
开发者ID:viewfinderco,项目名称:viewfinder,代码行数:19,代码来源:web.py

示例5: create_template_loader

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def create_template_loader(self, template_path):
        """Returns a new template loader for the given path.

        May be overridden by subclasses.  By default returns a
        directory-based loader on the given path, using the
        ``autoescape`` and ``template_whitespace`` application
        settings.  If a ``template_loader`` application setting is
        supplied, uses that instead.
        """
        settings = self.application.settings
        if "template_loader" in settings:
            return settings["template_loader"]
        kwargs = {}
        if "autoescape" in settings:
            # autoescape=None means "no escaping", so we have to be sure
            # to only pass this kwarg if the user asked for it.
            kwargs["autoescape"] = settings["autoescape"]
        if "template_whitespace" in settings:
            kwargs["whitespace"] = settings["template_whitespace"]
        return template.Loader(template_path, **kwargs) 
开发者ID:tp4a,项目名称:teleport,代码行数:22,代码来源:web.py

示例6: _get_handler

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def _get_handler(site_dir, StaticFileHandler):

    from tornado.template import Loader

    class WebHandler(StaticFileHandler):

        def write_error(self, status_code, **kwargs):

            if status_code in (404, 500):
                error_page = '{}.html'.format(status_code)
                if isfile(join(site_dir, error_page)):
                    self.write(Loader(site_dir).load(error_page).generate())
                else:
                    super().write_error(status_code, **kwargs)

    return WebHandler 
开发者ID:mkdocs,项目名称:mkdocs,代码行数:18,代码来源:serve.py

示例7: setUp

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def setUp(self):
        self.loader = Loader(os.path.join(os.path.dirname(__file__), "templates")) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:4,代码来源:template_test.py

示例8: create_template_loader

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def create_template_loader(self, template_path):
        settings = self.application.settings
        if "template_loader" in settings:
            return settings["template_loader"]
        kwargs = {}
        if "autoescape" in settings:
            # autoescape=None means "no escaping", so we have to be sure
            # to only pass this kwarg if the user asked for it.
            kwargs["autoescape"] = settings["autoescape"]
        return template.Loader(template_path, **kwargs) 
开发者ID:omererdem,项目名称:honeything,代码行数:12,代码来源:web.py

示例9: get

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def get(self):
        loader = Loader("politicos_api/templates")
        await self.write(loader.load("main.html").generate()) 
开发者ID:olhoneles,项目名称:politicos,代码行数:5,代码来源:main.py

示例10: get

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def get(self):
        handlers = []
        for x in self.application.handlers_api:
            # FIXME
            url = x.reverse().replace('?', '')
            handlers.append({'name': x.name, 'url': url})
        if handlers:
            handlers = sorted(handlers, key=lambda k: k['name'])
        loader = Loader('politicos_api/templates')
        content = loader.load('routes.html').generate(handlers=handlers)
        await self.write(content) 
开发者ID:olhoneles,项目名称:politicos,代码行数:13,代码来源:routes.py

示例11: write_error

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def write_error(self, status_code, **kwargs):
        loader = Loader('politicos_api/templates')
        if status_code == 404:
            self.write(loader.load('404.html').generate())
        else:
            self.write(loader.load('error.html').generate()) 
开发者ID:olhoneles,项目名称:politicos,代码行数:8,代码来源:base.py

示例12: get

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def get(self):
        loader = Loader('politicos_api/templates')
        await self.write(loader.load('developers.html').generate()) 
开发者ID:olhoneles,项目名称:politicos,代码行数:5,代码来源:developers.py

示例13: get

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def get(self):
        loader = Loader('politicos_api/templates')
        await self.write(loader.load('examples.html').generate()) 
开发者ID:olhoneles,项目名称:politicos,代码行数:5,代码来源:examples.py

示例14: render_script

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def render_script(self, name):

        scripts = ['boot', 'install']

        if name not in scripts:

            self.log.error(
                "'{}' is not correct script. Valid options are: '{}'"
                .format(name, scripts)
            )

            return None

        cluster = Cluster(mongo_db=self._mongo_db)
        self._get_group()
        path = cluster.get('path')
        tloader = template.Loader(path + '/templates')

        if cluster.get('frontend_https'):
            protocol = 'https'
        else:
            protocol = 'http'

        server_ip = cluster.get('frontend_address')
        server_port = cluster.get('frontend_port')

        if name == 'boot':
            p = self.boot_params
            p['protocol'] = protocol
            p['server_ip'] = server_ip
            p['server_port'] = server_port
            return tloader.load('templ_nodeboot.cfg').generate(p=p)

        if name == 'install':
            p = self.install_params
            p['protocol'] = protocol
            p['server_ip'] = server_ip
            p['server_port'] = server_port
            res = tloader.load('templ_install.cfg').generate(p=p)

            return res 
开发者ID:dchirikov,项目名称:luna,代码行数:43,代码来源:node.py

示例15: __init__

# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def __init__(self, path):
        self.loader = TemplateLoader(path) 
开发者ID:dalibo,项目名称:temboard,代码行数:4,代码来源:web.py


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