本文整理汇总了Python中jinja2.FileSystemLoader.load方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystemLoader.load方法的具体用法?Python FileSystemLoader.load怎么用?Python FileSystemLoader.load使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.FileSystemLoader
的用法示例。
在下文中一共展示了FileSystemLoader.load方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import load [as 别名]
def main():
env = Environment()
loader = FileSystemLoader(project_path)
template_opf = loader.load(env, opf_file)
template_ncx = loader.load(env, ncx_file)
#print template_opf.render(name='noisy')
#ctx = Context(loadContext());
#d = {'unique_identifier':'test', 'dc_title':'title_test', 'dc_lang':'lang_test'}
d = loadContext()
ctx = Context(env, blocks=d, name=opf_file, parent=env.globals)
template_opf.stream(**d).dump(project_path+'ekundelek_gen.opf') #unique_identifier='test', dc_title='title_test', dc_lang='lang_test') #jak dzia?a ** ?
template_ncx.stream(**d).dump(project_path+'ekundelek_gen.ncx')
#strim.dump(project_path+'ekundelek_gen.opf')
print 'Gotowe!'
pass
示例2: FileSystemLoader
# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import load [as 别名]
from jinja2 import Environment, FileSystemLoader
# Load index template.
my_template_path = '/srv/projects/intro_programming/intro_programming/notebooks/my_templates'
my_template_base_path = '/srv/projects/intro_programming/intro_programming/notebooks'
ipython_template_path = '/srv/projects/intro_programming/venv/lib/python3.4/site-packages/IPython/nbconvert/templates/html'
my_loader = FileSystemLoader(
[my_template_path, my_template_base_path, ipython_template_path])
env = Environment(loader=my_loader)
index_template = my_loader.load(env, 'index.tpl')
# Render template to file.
notebooks_path = '/srv/projects/intro_programming/intro_programming/notebooks/'
filepath = notebooks_path + 'index.html'
with open(filepath, 'w') as f:
f.write(index_template.render())
示例3: get_template
# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import load [as 别名]
def get_template(self, name):
loader = FileSystemLoader(os.getcwd())
return loader.load(self.settings['jinja2_env'], name)
示例4: ProxyApp
# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import load [as 别名]
class ProxyApp(object):
app = Klein()
ns = "{http://www.yale.edu/tp/cas}"
port = None
logout_instant_skew = 5
ticket_name = 'ticket'
service_name = 'service'
renew_name = 'renew'
pgturl_name = 'pgtUrl'
reactor = reactor
auth_info_resource = None
auth_info_callback = None
remoteUserHeader = 'Remote-User'
logout_patterns = None
logout_passthrough = False
verbose = False
proxy_client_endpoint_s = None
cas_client_endpoint_s = None
def __init__(self, proxied_url, cas_info,
fqdn=None, authorities=None, plugins=None, is_https=True,
excluded_resources=None, excluded_branches=None,
remote_user_header=None, logout_patterns=None,
logout_passthrough=False,
template_dir=None, template_resource='/_templates',
proxy_client_endpoint_s=None, cas_client_endpoint_s=None):
self.proxy_client_endpoint_s = proxy_client_endpoint_s
self.cas_client_endpoint_s = cas_client_endpoint_s
self.logout_passthrough = logout_passthrough
self.template_dir = template_dir
if template_dir is not None:
self.template_loader_ = FileSystemLoader(template_dir)
self.template_env_ = Environment()
self.templateStaticResource_ = self.create_template_static_resource()
if template_resource is not None:
if not template_resource.endswith('/'):
template_resource = "{0}/".format(template_resource)
if template_resource is not None and template_dir is not None:
static_base = "{0}static/".format(template_resource)
self.static = self.app.route(static_base, branch=True)(self.__class__.static)
self.static_base = static_base
self.template_resource = template_resource
if logout_patterns is not None:
self.logout_patterns = [parse_url_pattern(pattern) for pattern in logout_patterns]
for pattern in self.logout_patterns:
assert pattern is None or pattern.scheme == '', (
"Logout pattern '{0}' must be a relative URL.".format(pattern))
if remote_user_header is not None:
self.remoteUserHeader = remote_user_header
self.excluded_resources = excluded_resources
self.excluded_branches = excluded_branches
self.is_https = is_https
if proxied_url.endswith('/'):
proxied_url = proxied_url[:-1]
self.proxied_url = proxied_url
p = urlparse.urlparse(proxied_url)
self.p = p
self.proxied_scheme = p.scheme
netloc = p.netloc
self.proxied_netloc = netloc
self.proxied_host = netloc.split(':')[0]
self.proxied_path = p.path
self.cas_info = cas_info
cas_param_names = set([])
cas_param_names.add(self.ticket_name.lower())
cas_param_names.add(self.service_name.lower())
cas_param_names.add(self.renew_name.lower())
cas_param_names.add(self.pgturl_name.lower())
self.cas_param_names = cas_param_names
if fqdn is None:
fqdn = socket.getfqdn()
self.fqdn = fqdn
self.valid_sessions = {}
self.logout_tickets = {}
self._make_agents(authorities)
# Sort/tag plugins
if plugins is None:
plugins = []
content_modifiers = []
info_acceptors = []
cas_redirect_handlers = []
interceptors = []
access_control = []
for plugin in plugins:
if IResponseContentModifier.providedBy(plugin):
content_modifiers.append(plugin)
if IRProxyInfoAcceptor.providedBy(plugin):
info_acceptors.append(plugin)
if ICASRedirectHandler.providedBy(plugin):
cas_redirect_handlers.append(plugin)
if IResourceInterceptor.providedBy(plugin):
interceptors.append(plugin)
if IAccessControl.providedBy(plugin):
access_control.append(plugin)
self.info_acceptors = info_acceptors
content_modifiers.sort(key=lambda x: x.mod_sequence)
self.content_modifiers = content_modifiers
cas_redirect_handlers.sort(key=lambda x: x.cas_redirect_sequence)
self.cas_redirect_handlers = cas_redirect_handlers
interceptors.sort(key=lambda x: x.interceptor_sequence)
#.........这里部分代码省略.........
示例5: Application
# 需要导入模块: from jinja2 import FileSystemLoader [as 别名]
# 或者: from jinja2.FileSystemLoader import load [as 别名]
class Application(ErrorResponses):
middlewares = [CSRF()]
def __init__(self, settings=None):
self.settings = settings
self.subs = list()
self.app = self
self.loader = FileSystemLoader(settings.TEMPLATES_PATH)
def register(self, sub_class, path, *args, **kwargs):
log.debug('registred %s' % sub_class)
sub = sub_class(self, self, path, *args, **kwargs)
self.subs.append(sub)
return sub
def full_path(self, current):
return ''
def _match_path(self, match, path, subs):
match = dict()
for sub in subs:
submatch = sub.path.match(path)
if submatch:
# it is a good path
matched = submatch.groupdict()
if matched:
matched.update(match)
else:
matched = match
subpath = path[submatch.end():]
if subpath:
# try subs from this sub
o = self._match_path(matched, subpath, sub.subs)
if o[0]:
# a sub of this sub is a match return it
return o
else:
# if it matched but is not a subsub then it's the one
# that match (and to repeat it: it's not a sub of sub!)
return matched, sub
# else continue
# None matched
return None, None
def __call__(self, environ, start_response):
request = Request(environ)
for sub in self.subs:
log.debug('try to match %s' % sub)
# first match the domain if any try to match the path
path_match, sub = self._match_path(dict(), request.path, [sub])
if not sub:
continue
# found the good sub
request.path_match = path_match
for middleware in self.middlewares:
maybe_response = middleware.process_request_before_view(self, request)
if isinstance(maybe_response, Response):
return maybe_response(environ, start_response)
try:
response = sub(request)
except Exception: # XXX: improve this
print_exc()
response = self.internal_server_error(request)
for middleware in self.middlewares:
maybe_response = middleware.process_response_before_answer(self, request, response)
if isinstance(maybe_response, Response):
return maybe_response(environ, start_response)
return response(environ, start_response)
else:
for middleware in self.middlewares:
maybe_response = middleware.process_response_before_answer(self, request, response)
if isinstance(maybe_response, Response):
return maybe_response(environ, start_response)
return response(environ, start_response)
response = self.not_found(request)
for middleware in self.middlewares:
maybe_response = middleware.process_response_before_answer(self, request, response)
if isinstance(maybe_response, Response):
return maybe_response(environ, start_response)
return response(environ, start_response)
def render(self, request, path, **context):
response = Response(status=200)
template = self.loader.load(Environment(), path)
context['settings'] = self.settings
context['request'] = request
context['app'] = self.app
response.text = template.render(**context)
return response
def redirect(self, url):
return Response(status=302, location=url)