當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。