newbie : using python to generate web-pages

Robert Brewer fumanchu at amor.org
Fri Nov 28 15:38:15 EST 2003


Logan wrote:
> If there are not many places in your HTML where you have to substitute
> strings, then an approach like the following might be enough:
> 
>   html = """
>   <html>
>     <head>
>       <title>%s</title>
>     </head>
>     <body>
>     %s
>     </body>
>   </html>
>   """
> 
>   print html % ("The Title", "Content Area")
> 
> (You could also use placeholders like xxTitlexx, xxContentxx in 
> the string 'html' and replace them to create the output.)

And if you're going to use named placeholders, you could just use named
substitution (rather than writing your own parser to look for xx__xx):

html = """
<html>
    <head>
        <title>%(Title)s</title>
    </head>
    <body>
    %(Body)s
    </body>
</html>
"""

print html % ({"Title": "The Title", "Body": "Content Area"})



Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org





More information about the Python-list mailing list