[英]how to display the html code on a web page that is fetched from the db?
我正在將python和pyramid與mako模板一起用於顯示Web內容。 我有保存在數據庫中的html模板,現在我想將它們顯示在具有樣式和所有內容(工作url和圖像等)的網頁上,就像真正的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模板中的代碼正在運行,我對此很確定。
試試: ${structure: template}
,我不知道這是一個合適的選擇,但是http://chameleon.readthedocs.org/en/latest/reference.html#structure建議這樣做。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.