本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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
示例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"))
示例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)
示例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())
示例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)
示例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())
示例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())
示例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())
示例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
示例15: __init__
# 需要导入模块: from tornado import template [as 别名]
# 或者: from tornado.template import Loader [as 别名]
def __init__(self, path):
self.loader = TemplateLoader(path)