Pierre Quentel wrote:
On 12 jan, 04:26, Alan Harris-Reid <aharrisr...@googlemail.com> wrote:
Hi,

Does anyone know where I can find any decent dynamically-constructed
HTML control classes (dropdown list, table, input field, checkbox, etc.)
written in Python.  For example, for a HTML table I would like something
like...

MyTable =tml_table()       # instantiate class
MyTable.data =ata_list    # data-list (eg. cursor from SQL SELECT
statement)
MyTable.border = MyTable.width =87 MyTable.column_headers =ol_headers # list or tuple of column-headers
table_code =yTable.table.create()           # returns string
containing appropriate HTML code

I don't mind writing my own classes (it will be good practice for me),
but I don't want to re-invent the wheel if it can be avoided.

TIA,
Alan Harris-Reid

Hi,

There are a few modules to generate HTML from Python : there is a list
at http://wiki.python.org/moin/Templating, section HTML Generation
packages

With HTMLTags, your example would be coded like this :

from HTMLTags import *
table =ABLE(border=1,width~7)
table <=R(Sum([TD(header) for header in col_headers]))
for result in data_list:
    table <=R(Sum([TD(value) for value in result]))
print table

The operator <=eans "add child" in the DOM tree structure, it avoids
having to nest tags with brackets

- Pierre

Thanks Pierre. I can see this module being very useful. I have downloaded the code from the Activestate site (is that the latest version?) and will try it out as soon as possible.
Is HTMLTags Python3 compatible? (I am using 3.1).

Regards,
Alan Harris-Reid

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

Reply via email to