本文整理汇总了Python中tornado.template.Template.generate方法的典型用法代码示例。如果您正苦于以下问题:Python Template.generate方法的具体用法?Python Template.generate怎么用?Python Template.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.template.Template
的用法示例。
在下文中一共展示了Template.generate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode_literal_expression
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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"))
示例2: send_thanks
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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: GetDataFrameView
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
class GetDataFrameView(JSONRequestHandler):
def prepare(self):
tmpl_file = os.path.join(self.get_template_path(),"jqgrid_view.html")
if not(os.path.isdir(self.get_template_path())):
self.set_status(500)
self.finish("Template path does not exist")
return
with codecs.open(tmpl_file) as f:
self.tmpl = Template(f.read())
def get(self, objid):
import pandas as pd
# by default the object is placed in self.object
if not isinstance(context.object, pd.DataFrame):
self.set_status(500)
self.finish("Object exists, but is not a dataframe")
return
base = "http://{host}/pandas".format(host=self.request.host)
body = self.tmpl.generate(api_url=base,
objid=objid,
static_url=self.static_url)
self.write(body)
示例4: post
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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)
示例5: get
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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")
示例6: RequestLinkList
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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])
示例7: render
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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: Requestlink_list
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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])
示例9: _show_login_window
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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()
示例10: new
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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)
示例11: get
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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)
示例12: _entry_to_html
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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')
示例13: render
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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
# 需要导入模块: from tornado.template import Template [as 别名]
# 或者: from tornado.template.Template import generate [as 别名]
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)