如何在从db中获取的网页上显示html代码?

时间:2014-05-22 19:52:20

标签: python html

我正在使用python和金字塔与mako模板显示网页内容。我有保存在数据库中的html模板,现在我想在具有样式和所有内容(工作网址和图像等)的网页上显示它们,就像真正的html页面一样,但是从数据库获取。

输入是这样的:一般风格:

.footer-content-left { 
    -webkit-text-size-adjust: 80%; 
    -ms-text-size-adjust: 80%
} 

img {
    height: auto; 
    line-height: 100% 
}

h1 a:active {color:red} 

h2 a:active {color:red}

和实际内容:

<div style="-ms-text-size-adjust:none; -webkit-text-size-adjust:none; color:#d9fffd; font-size:12px">Awsome link 
    <a style="color:#d9fffd; font-weight:normal; text-decoration:none" href="%7Blink.url:link_foo">
        foo.bar
    </a> 
</div> etc.

使用以下预制器提取和编辑模板:

template = DBSession.query(Template).filter(Template.id == '1').first()  
template = transform(template.template) #editing the html code with premailer


return {'template': template}

html代码发送到mako模板,如下所示:${template},但最终结果一直只是纯文本,如上面的输入。 HTML模板中的代码正在运行,我确信这一点。

1 个答案:

答案 0 :(得分:0)

尝试:${structure: template},我不知道这是一个合适的选择,但http://chameleon.readthedocs.org/en/latest/reference.html#structure建议可能。

Found here