473,406 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Any python HTML generator libs?

Hi, everyone. Simply put, what I need most now is a python lib to
generate simple HTML.

I am now using XML to store my lab report records. I found python
really convinient to manipulate XML, so I want to make a small on-line
CGI program to help my colleagues to build their lab report records
into XML, for storage, HTML display (for others to browse) and search.

With python's standard lib, the DOM object could realize the XML
storage and search quite easily, but for HTML generation, it is a
great headache.

I tried to turn to the in-line server-side python script PSP(something
like asp and php) instead of CGI. However, since the report data is
always of very complex data structures, it is really hard to write most
things in-line. For example, a PCR reaction is expected to be shown in
this format or alike on a web browser:

PCR
Sample: Sm1032
Operater: SullivanZ
TimeStamp: hh:mm mm-dd-yyyy
Reaction:
Reagent1:
Name:XXXX
Concentration:XXXX mM
Volumn:XXX uL
Reagent2:
.........................
.........................

Since there are hundreds of PCR reaction and other operations in the
lab report, in-line PSP is not a suitable solution. But writing HTML
directly with print statement is a great pain.

Will XSTL be useful? Is my problem somewho related with XML-SIG?
Looking forward to your precious suggestion.

Mar 9 '06 #1
10 3306
Will XSTL be useful? Is my problem somewho related with XML-SIG?
Looking forward to your precious suggestion.

XSLT is powerful but a royal pain in the arse. Just writing some Python
to generate your HTML would probably be a lot easier for you.

--
Michael McGlothlin, tech monkey
Tub Monkey
http://www.tubmonkey.com/

Mar 9 '06 #2
Sullivan WxPyQtKinter napisa³(a):
Hi, everyone. Simply put, what I need most now is a python lib to
generate simple HTML.

I am now using XML to store my lab report records. I found python
really convinient to manipulate XML, so I want to make a small on-line
CGI program to help my colleagues to build their lab report records
into XML, for storage, HTML display (for others to browse) and search.

With python's standard lib, the DOM object could realize the XML
storage and search quite easily, but for HTML generation, it is a
great headache.


I use HTMLTemplate + ElementTree combo to generate static HTML documents
from data in XML files. Other way might be using "object oriented XSL",
as ll-xist is often advertized.

--
Jarek Zgoda
http://jpa.berlios.de/
Mar 9 '06 #3
Sullivan WxPyQtKinter wrote:
Hi, everyone. Simply put, what I need most now is a python lib to
generate simple HTML.

I am now using XML to store my lab report records. I found python
really convinient to manipulate XML, so I want to make a small on-line
CGI program to help my colleagues to build their lab report records
into XML, for storage, HTML display (for others to browse) and search.

With python's standard lib, the DOM object could realize the XML
storage and search quite easily, but for HTML generation, it is a
great headache.

I tried to turn to the in-line server-side python script PSP(something
like asp and php) instead of CGI. However, since the report data is
always of very complex data structures, it is really hard to write most
things in-line. For example, a PCR reaction is expected to be shown in
this format or alike on a web browser:

PCR
Sample: Sm1032
Operater: SullivanZ
TimeStamp: hh:mm mm-dd-yyyy
Reaction:
Reagent1:
Name:XXXX
Concentration:XXXX mM
Volumn:XXX uL
Reagent2:
........................
........................

Since there are hundreds of PCR reaction and other operations in the
lab report, in-line PSP is not a suitable solution. But writing HTML
directly with print statement is a great pain.

Will XSTL be useful? Is my problem somewho related with XML-SIG?
Looking forward to your precious suggestion.

The triple-quoted string with string substitution is your friend. Try
writing something(s) like:

results = {'secnum': 1, 'type': 'string', 'color': 'blue'}

print """\
<h1>Section %(secnum)s</h1>
<p>Elements of type %(type)s should be coloured %(color)s</p>
""" % results

Alternatively you might want to take a look at the HTMLgen module. It's
old, but still usable.

regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd www.holdenweb.com
Love me, love my blog holdenweb.blogspot.com

Mar 9 '06 #4
Sorry I am completely a green-hand in HTML. What is HTMLTemplate and
ElementTree? Would you please post some source code as an example?

Of course I would Google them to find out more.

Thank you so much.

Mar 9 '06 #5
That lib can help.
But still, I have to code a lot using that lib. Maybe my program is
quite strange, far from common.

Thank you, after all~!

Mar 9 '06 #6

Sullivan WxPyQtKinter wrote:
Hi, everyone. Simply put, what I need most now is a python lib to
generate simple HTML.

I am now using XML to store my lab report records. I found python
really convinient to manipulate XML, so I want to make a small on-line
CGI program to help my colleagues to build their lab report records
into XML, for storage, HTML display (for others to browse) and search.

With python's standard lib, the DOM object could realize the XML
storage and search quite easily, but for HTML generation, it is a
great headache.

I tried to turn to the in-line server-side python script PSP(something
like asp and php) instead of CGI. However, since the report data is
always of very complex data structures, it is really hard to write most
things in-line. For example, a PCR reaction is expected to be shown in
this format or alike on a web browser:

PCR
Sample: Sm1032
Operater: SullivanZ
TimeStamp: hh:mm mm-dd-yyyy
Reaction:
Reagent1:
Name:XXXX
Concentration:XXXX mM
Volumn:XXX uL
Reagent2:
........................
........................

Since there are hundreds of PCR reaction and other operations in the
lab report, in-line PSP is not a suitable solution. But writing HTML
directly with print statement is a great pain.

Will XSTL be useful? Is my problem somewho related with XML-SIG?
Looking forward to your precious suggestion.


If you don't mind a learning curve, you could use a CherryPy/Picket
combination - Picket is an XSLT 'filter' that uses 4Suite to transform
XML on the server:

http://www.cherrypy.org/wiki/Picket

XSLT is powerful but a bit...wearying, at first.

Gerard

Mar 9 '06 #7
Sullivan WxPyQtKinter a écrit :
Hi, everyone. Simply put, what I need most now is a python lib to
generate simple HTML.

I am now using XML to store my lab report records. I found python
really convinient to manipulate XML, so I want to make a small on-line
CGI program to help my colleagues to build their lab report records
into XML, for storage, HTML display (for others to browse) and search.

With python's standard lib, the DOM object could realize the XML
storage and search quite easily, but for HTML generation, it is a
great headache.


You may want to have a look at Kid:
http://kid.lesscode.org/trac/wiki/Si...ocessingRecipe
Mar 9 '06 #8

Jarek Zgoda wrote:
I use HTMLTemplate + ElementTree combo to generate static HTML documents
from data in XML files. Other way might be using "object oriented XSL",
as ll-xist is often advertized.


HTMLTemplate + ElementTree works for me too. Additionally I use CSS
(Cascading Style Sheets) to add style (e.g. fonts, colors and spacing). The
CSS also allows for different styles for display/print (e.g. not printing
menus). If you want to see artistic CSS google for "css Zen Garden" .

Nearly two years after initially using HTMLTemplate, the python code,
templates and css are easy to maintain. Whereas some code/markup written
with a python HTML generator is difficult to maintain.

Stephen D Evans
Mar 9 '06 #9
HTMLTemplate + ElementTree works for me too. Additionally I use CSS
(Cascading Style Sheets) to add style (e.g. fonts, colors and spacing). The
CSS also allows for different styles for display/print (e.g. not printing
menus). If you want to see artistic CSS google for "css Zen Garden" .

Nearly two years after initially using HTMLTemplate, the python code,
templates and css are easy to maintain. Whereas some code/markup written
with a python HTML generator is difficult to maintain.

CSS is awesome. It can lead to some real headaches when it comes to IE
though if you're doing anything very complex. Firefox, Safari, and Opera
are almost identical when it comes to CSS support now which makes life a
lot easier. I suggest using Javascript behaviors too whenever you need
to use Javascript. Pretty handy because it keeps your HTML clean and
lets you apply code in almost identical way to CSS.

I know of a UI tool (for Java on mobile devices) that lets you style the
UI of normal apps with CSS. That'd rock if it was available for Python
programs.

--
Michael McGlothlin, tech monkey
Tub Monkey
http://www.tubmonkey.com/

Mar 9 '06 #10
Steve Holden wrote:
Sullivan WxPyQtKinter wrote:
Hi, everyone. Simply put, what I need most now is a python lib to
generate simple HTML.

I am now using XML to store my lab report records. I found python
really convinient to manipulate XML, so I want to make a small on-line
CGI program to help my colleagues to build their lab report records
into XML, for storage, HTML display (for others to browse) and search.

With python's standard lib, the DOM object could realize the XML
storage and search quite easily, but for HTML generation, it is a
great headache.

I tried to turn to the in-line server-side python script PSP(something
like asp and php) instead of CGI. However, since the report data is
always of very complex data structures, it is really hard to write most
things in-line. For example, a PCR reaction is expected to be shown in
this format or alike on a web browser:

PCR
Sample: Sm1032
Operater: SullivanZ
TimeStamp: hh:mm mm-dd-yyyy
Reaction:
Reagent1:
Name:XXXX
Concentration:XXXX mM
Volumn:XXX uL
Reagent2:
........................
........................

Since there are hundreds of PCR reaction and other operations in the
lab report, in-line PSP is not a suitable solution. But writing HTML
directly with print statement is a great pain.

Will XSTL be useful? Is my problem somewho related with XML-SIG?
Looking forward to your precious suggestion.


The triple-quoted string with string substitution is your friend. Try
writing something(s) like:

results = {'secnum': 1, 'type': 'string', 'color': 'blue'}

print """\
<h1>Section %(secnum)s</h1>
<p>Elements of type %(type)s should be coloured %(color)s</p>
""" % results


Don't forget that you may need to escape the application's data for
inclusion in HTML:

results = {'secnum': 1, 'type': 'string', 'color': 'blue',
'user':'Matt Goodall <ma**@pollenation.net>'}

print """\
<h1>Section %(secnum)s</h1>
<p>Elements of type %(type)s should be coloured %(color)s</p>
<p>Contributed by: %(user)s</p>
""" % results

Will print:

<h1>Section 1</h1>
<p>Elements of type string should be coloured blue</p>
<p>Contributed by: Matt Goodall <ma**@pollenation.net></p>

The '<' and '>' surrounding my email address breaks the HTML.

To fix that you need to escape results['user'] with cgi.escape or
xml.sax.saxutils.escape. Oh, and don't forget to escape anything
destined for an HTML attribute differently, see sax.saxutils.quoteattr.

A triple-quoted string is beautifully simple but it's not quite as much
a friend as it might initially seem. ;-)

I don't intend to get into a XML- vs text- based templating flame war
;-) but, IMHO, the solution is to use a templating language that
understands where the value is used in the template.

Kid is a great example of an XML-based templating language but there are
many others. Some have probably been mentioned in this thread already.

Another interesting solutions is to use something like Nevow's tags module:

from nevow import flat, tags as T

results = {'secnum': 1, 'type': 'string', 'color': 'blue',
'user':'Matt Goodall <ma**@pollenation.net>'}

doc = T.div[
T.h1['Section ', results['secnum']],
T.p['Elements of type ', results['type'],
' should be coloured ', results['color']],
T.p['Contributed by: ', results['user']],
]

print flat.flatten(doc)

This time you get valid HTML with no effort whatsoever:

<div><h1>Section 1</h1><p>Elements of type string should be coloured
blue</p><p>Contributed by: Matt Goodall
&lt;ma**@pollenation.net&gt;</p></div>

You even get to write HTML in a slightly more Pythonic way (even if it
does abuse Python just a little :wink:), but Nevow will happily load a
template containing actual XHTML from disk if you prefer.

The only real "problem" using Nevow for this is that you will need to
install Twisted too. I suspect you'll find a couple of Nevow tag
implementations that don't need Twisted if you ask Google.

Anyway! This was just to demonstrate an alternate approach than to
evangelise about Nevow. I hope it was at least interesting. :)

Cheers, Matt

Nevow:
http://divmod.org/trac/wiki/DivmodNevow
Twisted:
http://twistedmatrix.com/trac

--
__
/ \__ Matt Goodall, Pollenation Internet Ltd
\__/ \ w: http://www.pollenation.net
__/ \__/ e: ma**@pollenation.net
/ \__/ \ t: +44 (0)113 2252500
\__/ \__/
/ \ Any views expressed are my own and do not necessarily
\__/ reflect the views of my employer.
Mar 10 '06 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Mikey At Work | last post by:
I'm looking for opinions on the several HTML documentation generators available for Python. We're trying to standardize the documentaion used for an upcoming project. Specifically, I'm looking...
0
by: Premshree Pillai | last post by:
Hello people, I recently updated one of my Python scripts -- pyAlbum.py This is a simple, command-line based, lightweight Python script to create an image album. Of course, there are plenty...
1
by: Peter Newman | last post by:
I'm embedding a Python interpreter into a project, and compiling with MSVC. It all runs great in the "Debug" configuration, but everything gets scary when I switch to "Release". I've read about...
2
by: wipit | last post by:
I need to process a HTML form in python. I'm using urllib2 and HTMLParser to handle the html. There are several steps I need to take to get to the specific page on the relevant site the first of...
4
by: Pierre Imbaud | last post by:
Hi, Im looking for a way to display some python code in html: with correct indentation, possibly syntax hiliting, dealing correctly with multi-line comment, and... generating valid html code if...
8
by: flit | last post by:
Hello All, I am trying to get information from a form and send it to a python script without success.. Here is my objective: User enters data in form --form send variables to python script...
4
by: JediKnight83 | last post by:
I want to generate a script that produces html code. I have tried out must parts of the code from the shell .Somehow I always get errors if I check the modul. please help me find the syntax...
5
by: Johannes Bauer | last post by:
Hello group, I'm trying to use a htmllib.HTMLParser derivate class to parse a website which I fetched via httplib.HTTPConnection().request().getresponse().read(). Now the problem is: As soon as...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.