简体   繁体   中英

how to display the html code on a web page that is fetched from the db?

I'm using python and pyramid with mako templates on displaying web content. I have html templates that are saved in a database, and now i want to display them on a web page with styles and everything(working urls and images etc.), just like a real html page would be, but fetched from the db.

Input is something like this: general styles:

.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}

and actual content:

<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.

Templates are fetched and edited with a premailer like this:

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


return {'template': template}

html code is sent to mako template like this: ${template} , but end result has always been just plain text, like input in above. And code in a HTML templates is working, i'm sure about that.

Try: ${structure: template} , I don't know that this is an appropriate choice but http://chameleon.readthedocs.org/en/latest/reference.html#structure suggested it might.

Found here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM