HTML generation vs PSP vs Templating Engines

Sells, Fred fred at adventistcare.org
Wed Nov 16 18:30:24 EST 2005


If this is your first try, use cgi, cgitb and html % dictionary as suggested
in this thread.  If your db is mysql, you can actually use os.popen() (or
equivalent) to run a  'mysql -html -e "select * from yaddayadda" to return
html.  you can make that look prettier with css.
here's a quick and dirty I just did.
===================================snip=====================================
=======================
#!/usr/bin/python
import os, string, sys, time, cgi, cgitb
cgitb.enable(display=1)
import ezcgi
HTML = """<HTML><HEAD>
<style type="text/css" >
       table {cell-padding:2; cell-spacing:2; font-family:Arial;}
       th { background-color: lightblue; cell-padding:5; cell-spacing:5;}
       td { background-color: lightgray; padding:5; spacing:5;
font-size:mediumm;}
</style>
<TITLE>Snapshot of Administrative Bed Holds</TITLE>
</HEAD>
<BODY>
<BR>
<H1><font color=darkred>Current Administrative Bed Holds at all
Facilities</font></H1>
%s
<HR>
%s
<HR>
<H6>Copyright (C) 1996-2005, Adventist Care Centers, Inc.  For Internal Use
Only</H6>
<A HREF="http://acc.sunbelt.org">Home</A>|
<A HREF="http://acc.sunbelt.org/rwb?P001=logout">Logout</A>
</BODY></HTML>"""

COMMAND = ['mysql --host=acaredb --user=acare --password=acare -D census -H
-e ', 
           '"SELECT facility,wrb Room,description Reason,startdate, note
Explanation',
           'FROM admin_bed_holds h, abhreasons r '
           'WHERE h.reason=r.id   ',
           ' ORDER BY facility;"']
COMMAND = ' '.join(COMMAND)

def select_holds():
        x = os.popen(COMMAND)
        table = x.read(6000)
        return HTML % ('', table)

def execute():
    if ezcgi.is_authenticated():
        print ezcgi.HTML_CONTENT_TYPE
        print select_holds()
    else: 
        ezcgi.authenticate_user()
        
if __name__=='__main__':
    #print ezcgi.PLAIN_CONTENT_TYPE
    #print COMMAND
    execute()
===========================snip=============================================
=========================
-----Original Message-----
From: pkassianidis at gmail.com [mailto:pkassianidis at gmail.com]
Sent: Wednesday, November 16, 2005 11:32 AM
To: python-list at python.org
Subject: HTML generation vs PSP vs Templating Engines


Hello everybody,

I am in the process of writing my very first web application in Python,
and I need a way to
generate dynamic HTML pages with data from a database.  I have to say I
am overwhelmed
by the plethora of different frameworks, templating engines, HTML
generation tools etc that
exist. After some thought I decided to leave the various frameworks
aside for the
time being and use mod_python.publisher along with some means of
generating HTML on
the fly.
Could someone that has used all the different ways mentioned above for
dynamic HTML
content, suggest what the pros and cons of the different methods are?

  Thank you very much in advance

                  Panos

-- 
http://mail.python.org/mailman/listinfo/python-list

---------------------------------------------------------------------------
The information contained in this message may be privileged and / or
confidential and protected from disclosure. If the reader of this message is
not the intended recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited. If you
have received this communication in error, please notify the sender
immediately by replying to this message and deleting the material from any
computer.
---------------------------------------------------------------------------



More information about the Python-list mailing list