Re: Any python HTML generator libs?
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- Reaction: Reagent1: Name: Concentration: 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 \ h1Section %(secnum)s/h1 pElements 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 [EMAIL PROTECTED]'} print \ h1Section %(secnum)s/h1 pElements of type %(type)s should be coloured %(color)s/p pContributed by: %(user)s/p % results Will print: h1Section 1/h1 pElements of type string should be coloured blue/p pContributed by: Matt Goodall [EMAIL PROTECTED]/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 [EMAIL PROTECTED]'} 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: divh1Section 1/h1pElements of type string should be coloured blue/ppContributed by: Matt Goodall lt;[EMAIL PROTECTED]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: [EMAIL PROTECTED] / \__/ \t: +44 (0)113 2252500 \__/ \__/ / \ Any views expressed are my own and do not necessarily \__/ reflect the views of my employer. -- http://mail.python.org/mailman/listinfo/python-list
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- Reaction: Reagent1: Name: Concentration: 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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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- Reaction: Reagent1: Name: Concentration: 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 \ h1Section %(secnum)s/h1 pElements 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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. -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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~! -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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- Reaction: Reagent1: Name: Concentration: 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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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/SimpleXmlDocumentProcessingRecipe -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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 -- http://mail.python.org/mailman/listinfo/python-list
Re: Any python HTML generator libs?
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/ -- http://mail.python.org/mailman/listinfo/python-list