- 論壇徽章:
- 0
|
TurboGears中,數(shù)據(jù)庫(kù)使用 gbk , 模板保存在數(shù)據(jù)庫(kù)中,取出模板字符串,及內(nèi)容,保存到文件中。
@expose()
def publish(self):
pages = Page.selectBy(p_filename="test.html")
for page in pages:
template_def = codecs.encode(page.p_template, 'gbk')
#template_def = page.p_template
nameSpace = {u'title': u'Hello World Example',
u'contents': codecs.encode(page.p_name,'gbk')}
t = Template(template_def, searchList = [nameSpace])
#f_out = codecs.open(SAVE_PATH + page.p_filename, 'w', 'gbk')
f_out = open(SAVE_PATH + page.p_filename, 'w')
f_out.write(t.__str__())
f_out.close()
本文來(lái)自ChinaUnix博客,如果查看原文請(qǐng)點(diǎn):http://blog.chinaunix.net/u/4614/showart_138479.html |
|