本文整理汇总了Python中tornado.template.Template类的典型用法代码示例。如果您正苦于以下问题:Python Template类的具体用法?Python Template怎么用?Python Template使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Template类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Requestlink_list
def Requestlink_list(self, ResourceListName, ResourceList, PluginInfo):
link_list = []
for Name, Resource in ResourceList:
Chunks = Resource.split('###POST###')
URL = Chunks[0]
POST = None
Method = 'GET'
if len(Chunks) > 1: # POST
Method = 'POST'
POST = Chunks[1]
Transaction = self.requester.get_transaction(True, URL, Method, POST)
if Transaction is not None and Transaction.found:
RawHTML = Transaction.get_raw_response_body()
FilteredHTML = self.reporter.sanitize_html(RawHTML)
NotSandboxedPath = self.plugin_handler.dump_output_file("NOT_SANDBOXED_%s.html" % Name, FilteredHTML,
PluginInfo)
logging.info("File: NOT_SANDBOXED_%s.html saved to: %s", Name, NotSandboxedPath)
iframe_template = Template("""
<iframe src="{{ NotSandboxedPath }}" sandbox="" security="restricted" frameborder='0'
style="overflow-y:auto; overflow-x:hidden;width:100%;height:100%;" >
Your browser does not support iframes
</iframe>
""")
iframe = iframe_template.generate(NotSandboxedPath=NotSandboxedPath.split('/')[-1])
SandboxedPath = self.plugin_handler.dump_output_file("SANDBOXED_%s.html" % Name, iframe, PluginInfo)
logging.info("File: SANDBOXED_%s.html saved to: %s", Name, SandboxedPath)
link_list.append((Name, SandboxedPath))
plugin_output = dict(PLUGIN_OUTPUT)
plugin_output["type"] = "Requestlink_list"
plugin_output["output"] = {"ResourceListName": ResourceListName, "link_list": link_list}
return ([plugin_output])
示例2: send_thanks
def send_thanks(recepient, fundraiser_name, amount, donation_date):
# bit messy, make this cleaner
donation_date = (donation_date + timedelta(hours=10)).strftime('%H:%M:%S %Y-%m-%d AEST')
basepath = os.path.dirname(__file__)
filepath = os.path.join(basepath, 'email.html')
with open(filepath) as f:
raw_template = f.read()
t = Template(raw_template)
parsed_template = t.generate(title='{} - Thank you'.format(fundraiser_name),
donation_date=donation_date,
fundraiser_name=fundraiser_name,
donation_amount=amount)
message = MIMEMultipart('related')
msg_html = MIMEText(parsed_template, 'html')
message.attach(msg_html)
message['Subject'] = '{} - Thank you'.format(fundraiser_name)
message['From'] = FROM
message['To'] = recepient
send(recepient, FROM, message.as_string())
示例3: post
def post(self):
error = None
try:
username = self.request.arguments['username'][0]
if len(username) == 0:
raise Exception('bad username')
"""if get_user(username) == True:
error = 'Username already exists.'
raise Exception()"""
except:
if not error == None:
error = 'A non-zero length username is required.'
try:
password = self.request.arguments['password'][0]
if len(password) == 0:
raise Exception('bad password')
except:
if not error == None:
error = 'A non-zero length password is required.'
print username
"""add_account(username, password)"""
if error == None:
t = Template(open('templates/client_sample.html',
'r').read())
client_sample_code = t.generate(username=username)
self.render('templates/index.html', code=client_sample_code)
else:
self.render('templates/register.html', error=error)
示例4: get
def get(self, id):
try:
dog = db_session.query(Dog).filter(Dog.id == id).one()
t = Template('<img alt="dog_image" src="data:image/jpeg;base64,{{ img }}" />')
self.write(t.generate(img=dog.image))
except:
self.write("Dog not found")
示例5: RequestLinkList
def RequestLinkList(self, ResourceListName, ResourceList, PluginInfo):
# for Name, Resource in Core.Config.GetResources('PassiveRobotsAnalysisHTTPRequests'):
LinkList = []
for Name, Resource in ResourceList:
Chunks = Resource.split('###POST###')
URL = Chunks[0]
POST = None
Method = 'GET'
if len(Chunks) > 1: # POST
Method = 'POST'
POST = Chunks[1]
Transaction = self.requester.GetTransaction(True, URL, Method, POST)
if Transaction.Found:
RawHTML = Transaction.GetRawResponseBody()
FilteredHTML = self.reporter.sanitize_html(RawHTML)
NotSandboxedPath = self.plugin_handler.DumpOutputFile("NOT_SANDBOXED_" + Name + ".html",
FilteredHTML, PluginInfo)
logging.info("File: " + "NOT_SANDBOXED_" + Name + ".html" + " saved to: " + NotSandboxedPath)
iframe_template = Template("""
<iframe src="{{ NotSandboxedPath }}" sandbox="" security="restricted" frameborder = '0' style = "overflow-y:auto; overflow-x:hidden;width:100%;height:100%;" >
Your browser does not support iframes
</iframe>
""")
iframe = iframe_template.generate(NotSandboxedPath=NotSandboxedPath.split('/')[-1])
SandboxedPath = self.plugin_handler.DumpOutputFile("SANDBOXED_" + Name + ".html", iframe,
PluginInfo)
logging.info("File: " + "SANDBOXED_" + Name + ".html" + " saved to: " + SandboxedPath)
LinkList.append(( Name, SandboxedPath ))
plugin_output = dict(PLUGIN_OUTPUT)
plugin_output["type"] = "RequestLinkList"
plugin_output["output"] = {"ResourceListName": ResourceListName, "LinkList": LinkList}
return ([plugin_output])
示例6: new
def new():
'''Create a new ticket.
$EDITOR will be opened and used to edit the case. The case
template has an "header" in .yaml format. "Title", "Project",
"Area", "Files", etc. are all available fields.
The body of the ticket is separated by "---".
Example:
>>> new
'''
tmpl = Template('''Title: <title>
Project: <project>
# Area: <area>
# Assign to: {{ user.fullname }}
# Priority: Need to fix
# Parent: <id>
# Milestone: Infrastructure and Internal Errors
# Tags: <list>
---
<Insert description here>
''') # noqa
header = tmpl.generate(user=CURRENT_USER).decode('utf-8')
with editor.writing(header=header) as text:
editor.abort_if_empty(text)
params = text.get_params_for_new()
FBCase.new(**params)
示例7: render
def render(template_file, data=None):
if (data is None):
data = {}
t = Template(open("public/views/{0}".format(template_file), "r").read())
return t.generate(**data)
示例8: _show_login_window
def _show_login_window(self, next="/", message=None, login_template=None):
if not login_template:
login_template = self.settings.get('login_template', LOGIN_PAGE_TEMPLATE)
t = Template(login_template)
html = t.generate(next=next, message=message)
self.write(html)
self.finish()
示例9: test_unicode_literal_expression
def test_unicode_literal_expression(self):
# Unicode literals should be usable in templates. Note that this
# test simulates unicode characters appearing directly in the
# template file (with utf8 encoding), i.e. \u escapes would not
# be used in the template file itself.
template = Template(utf8(u'{{ "\u00e9" }}'))
self.assertEqual(template.generate(), utf8(u"\u00e9"))
示例10: get
def get(self):
b = Template(string)
books=['Learning Python', 'Programming Collective Intelligence',
'Restful Web Services']
content = b.generate(title='Home Page',
header='Books that are great',
books=books)
self.write(content)
示例11: _entry_to_html
def _entry_to_html(self, entry):
t = Template(self._html_entry)
return text_type(t.generate(source=entry.source,
anchor=entry.anchor, id=entry.id,
link=entry.link, title=entry.title,
author=entry.author, updated=entry.updated,
updated_str=self._date_to_str(entry.updated),
content=entry.content), 'UTF-8')
示例12: generate
def generate(codes, output_path = './qrmaster',
url='http://test.com', title='',
img_path=None):
"""codes are tuples in the form: (code, id)"""
module_path, _ = path.split(__file__)
css_file_name = 'style.css'
template_path = path.join(module_path, 'template.html')
css_path = path.join(module_path, css_file_name)
output_file = path.join(output_path, 'qrmaster.html')
o_css_path = path.join(output_path, css_file_name)
files_path = path.join(output_path, 'qrmaster')
if not path.exists(files_path):
makedirs(files_path)
if img_path:
_, img_file_name = path.split(img_path)
o_img_path = path.join(output_path, img_file_name)
copyfile(img_path, o_img_path)
else:
o_img_path = ''
copyfile(css_path, o_css_path)
data = []
for c in codes:
qr = qrcode.QRCode(
version = 1,
box_size = 5,
border = 0,
error_correction =
qrcode.constants.ERROR_CORRECT_H
)
full_url = urljoin(url, c[0])
c.append(full_url)
data.append(c)
qr.add_data(full_url)
qr.make()
qr_path = path.join(files_path, c[0]+'.svg')
qr.make_image(
image_factory=qrcode.image.svg.SvgImage).save(
qr_path)
with open(template_path, 'r') as f:
tmp = f.read()
html = Template(tmp).generate(data=data,
files_path=files_path,
title=title,
img_path=img_file_name)
with open(output_file, 'w') as f:
f.write(
html.decode('utf-8')
)
示例13: render
def render(tpl_text, **kwargs):
"""
render a template
:param tpl_text: template text
:param context: dict object
:return: str
"""
tpl = Template(tpl_text)
return tpl.generate(**kwargs).decode("utf-8")
示例14: test_try
def test_try(self):
template = Template(utf8("""{% try %}
try{% set y = 1/x %}
{% except %}-except
{% else %}-else
{% finally %}-finally
{% end %}"""))
self.assertEqual(template.generate(x=1), b"\ntry\n-else\n-finally\n")
self.assertEqual(template.generate(x=0), b"\ntry-except\n-finally\n")
示例15: render
def render(tpl_text, context):
"""
render a template
:param tpl_text: template text
:param context: dict object
:return: str
"""
tpl = Template(tpl_text)
return tpl.generate(context)