本文整理汇总了Python中simpletemplate.SimpleTemplate类的典型用法代码示例。如果您正苦于以下问题:Python SimpleTemplate类的具体用法?Python SimpleTemplate怎么用?Python SimpleTemplate使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SimpleTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: listurl
def listurl(_request):
res = Response()
rsslist = Rssurl.select()
t = SimpleTemplate(file_path=relativepath('urllist.html'))
body = t.render({'rsslist': rsslist})
res.set_body(body)
return res
示例2: get_form
def get_form(self,value=''):
body = ("""<input type="text" name"${name}"
value="${value}" """
"""${attrs} />""")
t = SimpleTemplate(body)
return t.render({'name':self.name, 'value':value,
'attrs':self.attrs})
示例3: test_process
def test_process(self):
with mock.patch('simpletemplate.SimpleTemplate.process') as m:
m.return_value = [0, '']
t = SimpleTemplate('value')
o = t.render()
self.assertEqual(m.call_count, 1)
self.assertEqual('', o)
示例4: test_handle_value2
def test_handle_value2(self):
dic = {'value':'actual'}
t = SimpleTemplate('${value}value')
m = value_pat.search(t.lines[0])
self.assertIsNotNone(m)
cur, o = t.handle_value(m, 0, dic)
self.assertEqual(0, cur)
self.assertEqual('actualvalue\n', o)
示例5: test_handle_value
def test_handle_value(self):
t = SimpleTemplate('${value}')
m = value_pat.search(t.lines[0])
self.assertIsNotNone(m)
dict = {'value':'actual'}
cur, o = t.handle_value(m, 0, dict)
self.assertEqual(0, cur)
self.assertEqual('actual\n', o)
示例6: index
def index(_request, d={'counter': '0'}):
body = """<html><body><p>${counter}</p></body></html>"""
res = Response()
t = SimpleTemplate(body)
body = t.render(d)
d['counter'] = str(int(d['counter']) + 1)
res.set_body(body)
return res
示例7: index
def index(_request, foo='', d={'counter': '0'}):
body = base_body % ('<p>Logged in!</p>')
res = Response()
t = SimpleTemplate(body)
body = t.render(d)
d['counter'] = str(int(d['counter']) + 1)
res.set_body(body)
return res
示例8: login_form
def login_form(_request, values={}, errors={}):
body = base_body % ('${form.display(values, errors)}')
res = Response()
t = SimpleTemplate(body)
values['password'] = ''
body = t.render({'form': loginform, 'values': values, 'errors': errors})
res.set_body(body)
return res
示例9: login_form
def login_form(_request, values={}, errors={}):
res=Response()
t=SimpleTemplate(file_path=relativepath('form.html'))
values['password']=''
body=t.render({'form':loginform, 'values':values, 'errors':errors,
'message':u'ログイン'})
res.set_body(body)
return res
示例10: get_add_form
def get_add_form(values={}, errors={}):
res = Response()
t = SimpleTemplate(file_path=relativepath('form.html'))
body = t.render({'message': 'RSS巡回用URLの追加',
'form': addform,
'values': values, 'errors': errors})
res.set_body(body)
return res
示例11: display
def display(self, values={}, errors={}):
container = ""
for f in self.forms:
container += f.display(values.get(f.name, ""), errors.get(f.name, ""))
container += """<br clear="all" />"""
body = """<form ${attrs}>\n""" """${container}\n""" """</form>\n"""
t = SimpleTemplate(body)
return t.render({"attrs": self.attrs, "container": container})
示例12: get_label
def get_label(self, error):
body = ("""<label for="${name}">${label}\n"""
"""$if error:\n"""
"""<span class="error">${error}</span>\n"""
"""$endif\n"""
"""</label>""")
t = SimpleTemplate(body)
return t.render({'name': self.name, 'label': self.label, 'error': error})
示例13: test_call_stbookmarkform
def test_call_stbookmarkform(self):
p=path.join(path.dirname(__file__),"stbookmarkform.html")
t=SimpleTemplate(file_path=p)
value_dic={}
value_dic["message"]="Message"
value_dic["title"]="Title"
value_dic["url"]="URL"
value_dic["bookmarks"]=("Yahoo!","http://www.yahoo.co.jp")
body=t.render(value_dic)
print body
示例14: display
def display(self, values={}, errors={}):
container = ''
for f in self.forms:
container += f.display(values.get(f.name, ''), errors.get(f.name, ''))
container += """<br clear="all" />"""
body = ("""<form ${attrs}>\n"""
"""${container}\n"""
"""</form>\n""")
t = SimpleTemplate(body)
return t.render({'attrs': self.attrs, 'container': container})
示例15: test_process2
def test_process2(self):
t = SimpleTemplate("""
$if True:
test
$endif
""")
body = t.render({})
self.assertEqual("""
test
""", body)