Web development with Python 3.1

Albert Hopkins marduk at letterboxes.org
Wed Oct 28 18:40:40 EDT 2009


On Wed, 2009-10-28 at 15:32 +0200, Dotan Cohen wrote:
> > def index(request):
> >    unmaintanable_html = """
> > <html>
> >  <head>
> >    <title>Index</title>
> >  </head>
> >  <body>
> >    <h1>Embedded HTML is a PITA</h1>
> >    <p>but some like pains...</p>
> >  </body>
> > </html>
> > """
> >    return HttpResponse(unmaintanable_html)
> >
> 
> And if I need to add a variable or three in there? Static HTML I can
> do without Python.
> 

Put the variables in  a dict and then return
    
    unmaintanable_html % varDict

Or, if you want the the static HTML in a file then you can return

    open(static_html_filename).read() % varDict

Add any complexity beyond that though and you're pretty much on your way
to writing a template engine ;-)

-a





More information about the Python-list mailing list