473,320 Members | 1,719 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,320 software developers and data experts.

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

Nov 22 '05 #1
18 4923
pk**********@gmail.com wrote:
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. (snip) After some thought I decided to leave the various frameworks
aside for the
time being and use mod_python.publisher


I know this is not exactly an answer to your question, but have you
tried Django ?
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Nov 22 '05 #2
pk**********@gmail.com wrote:
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. (snip) After some thought I decided to leave the various frameworks
aside for the
time being and use mod_python.publisher


I know this is not exactly an answer to your question, but have you
tried Django ?
--
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'o****@xiludom.gro'.split('@')])"
Nov 22 '05 #3
> 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.


I kind of like KID templates the most, you can easyly work with them in any
HTML authoring software, they are easy to use (prety much pythonic).
--
damjan
Nov 22 '05 #4
> 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.


I kind of like KID templates the most, you can easyly work with them in any
HTML authoring software, they are easy to use (prety much pythonic).
--
damjan
Nov 22 '05 #5
I just do the following:

I store the form data as a pickeled dictionary. Then I create my
HTML form with something like this:

HTMLout="""<HTML><BODY>......
.......
<INPUT NAME="field1" value=%(field1)s>
<INPUT NAME="field2" value=%(field2)s>
<INPUT NAME="field3" value=%(field3)s>'''

where the field1, field2 etc era the fields on my form.

Then finally:

print HTMLout % dict

where dict has all the values that I previously pickled.
You have to do some additional trickery for <SELECT> type fields
and checkboxes and so on but its really not difficult.

Nov 22 '05 #6
I just do the following:

I store the form data as a pickeled dictionary. Then I create my
HTML form with something like this:

HTMLout="""<HTML><BODY>......
.......
<INPUT NAME="field1" value=%(field1)s>
<INPUT NAME="field2" value=%(field2)s>
<INPUT NAME="field3" value=%(field3)s>'''

where the field1, field2 etc era the fields on my form.

Then finally:

print HTMLout % dict

where dict has all the values that I previously pickled.
You have to do some additional trickery for <SELECT> type fields
and checkboxes and so on but its really not difficult.

Nov 22 '05 #7
With Karrigell (http://karrigell.sf.net/), all you need to know is
Python and HTML.
No templates, no python-like or special languages, only pure and simple
python.

You can embedd python into html or, if it better suits your programming
tyle, you can embed html into python. Why don't you give it a try?

Nov 22 '05 #8
With Karrigell (http://karrigell.sf.net/), all you need to know is
Python and HTML.
No templates, no python-like or special languages, only pure and simple
python.

You can embedd python into html or, if it better suits your programming
tyle, you can embed html into python. Why don't you give it a try?

Nov 22 '05 #9
has
pk**********@gmail.com wrote:
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?


Not used them all - as you say, there's a plethora of options - but to
give you a general idea of the territory...

First choice you have is between HTML generators vs. HTML templating
systems:

- HTML generators create all markup from scratch. Useful when producing
arbitrary markup/layout whose entire structure must be determined
programmatically, e.g. applying paragraph and character styling to a
big chunk of text, creating arbitrary HTML form layouts based on other
input. Examples: htmlgen (crusty, HTML 3.1-era), Nevow's Stan engine.

- HTML templates insert individual items of data into a mostly static
block of HTML markup written in advance by e.g. a graphic designer.
Useful when creating documents that are fairly regular in structure -
most fall into this category - as it's much easier to create the
repetitious parts using standard HTML editing tools than write code to
produce it all programmatically.

Sometimes you might combine the two methods, using an HTML generator to
create sections of markup from arbitrary input which is then inserted
into a full-page template to produce the finished HTML document.
Assuming a templating-based solution is the appropriate choice for you
(which it most likely is), there are three general approaches to choose
from:

1. Systems that embed markup in code. This is a fairly small category.
It's fairly programmer-friendly since you've direct access to all
language features, but hostile to web designers as you have to pull
your HTML markup apart and insert it into program code to produce the
final template, making it a pain to modify that markup later. Examples:
ad-hoc solutions using Python's string interpolation, the Quixote
framework's built-in templating support, Karrigell (though it supports
some aspects of approach 2 as well).

2. Systems that embed code in markup. This is the most common category
with a fair amount of variety and capabilities to choose from. Lots of
obviously PHP/ASP-inspired designs. Two sub-categories: systems that
embed standard Python code, e.g. PSP, and systems that embed a custom
language, e.g. Cheetah. Some provide no restrictions on what you can
get up to within embedded code, others restrict functionality to
enforce a strict separation between presentation logic and model logic.
Embedding styles also vary: some mix code statements and markup
directly (e.g. Cheetah), some embed code statements in special <%...%>
style tags (e.g. PSP), some hide all code within HTML tag attributes
(e.g. TAL, Kid), providing varying degrees of designer-friendliness as
a result.

3. DOM-style systems. This is a more recent arrival and a smaller
category. These systems completely separate markup from presentation
logic. Selected HTML elements are flagged using specific named tag
attributes (e.g. id="somename") or simple compiler directives, e.g.
(nevow:render="somename"); the template is then compiled into a simple
templating-oriented (i.e. not w3c) DOM, allowing these elements to be
manipulated programmatically by standard Python scripts. Very designer
and developer friendly, although less experienced programmers may find
the higher level of abstraction involved a bit offputting. Examples:
PyMeld, HTMLTemplate [1], Nevow.Render.
For a fairly extensive list of available systems, see
<http://wiki.python.org/moin/WebProgramming>. Unfortunately they're not
well categorised there, but I can't think of a better, up-to-date list
off the top of my head and most will provide decent overviews so it
shouldn't take too long to take a quick look at each.

Note that some templating engines are embedded into larger web
programming frameworks and may or may not be usable independently.
Conversely, some web frameworks may be coupled to a specific templating
system, while others allow you to choose your own.

HTH

has

--
[1] Disclaimer: I wrote HTMLTemplate. Also, shameless plug:
<http://freespace.virgin.net/hamish.sanderson/htmltemplate.html>

Nov 22 '05 #10
has
pk**********@gmail.com wrote:
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?


Not used them all - as you say, there's a plethora of options - but to
give you a general idea of the territory...

First choice you have is between HTML generators vs. HTML templating
systems:

- HTML generators create all markup from scratch. Useful when producing
arbitrary markup/layout whose entire structure must be determined
programmatically, e.g. applying paragraph and character styling to a
big chunk of text, creating arbitrary HTML form layouts based on other
input. Examples: htmlgen (crusty, HTML 3.1-era), Nevow's Stan engine.

- HTML templates insert individual items of data into a mostly static
block of HTML markup written in advance by e.g. a graphic designer.
Useful when creating documents that are fairly regular in structure -
most fall into this category - as it's much easier to create the
repetitious parts using standard HTML editing tools than write code to
produce it all programmatically.

Sometimes you might combine the two methods, using an HTML generator to
create sections of markup from arbitrary input which is then inserted
into a full-page template to produce the finished HTML document.
Assuming a templating-based solution is the appropriate choice for you
(which it most likely is), there are three general approaches to choose
from:

1. Systems that embed markup in code. This is a fairly small category.
It's fairly programmer-friendly since you've direct access to all
language features, but hostile to web designers as you have to pull
your HTML markup apart and insert it into program code to produce the
final template, making it a pain to modify that markup later. Examples:
ad-hoc solutions using Python's string interpolation, the Quixote
framework's built-in templating support, Karrigell (though it supports
some aspects of approach 2 as well).

2. Systems that embed code in markup. This is the most common category
with a fair amount of variety and capabilities to choose from. Lots of
obviously PHP/ASP-inspired designs. Two sub-categories: systems that
embed standard Python code, e.g. PSP, and systems that embed a custom
language, e.g. Cheetah. Some provide no restrictions on what you can
get up to within embedded code, others restrict functionality to
enforce a strict separation between presentation logic and model logic.
Embedding styles also vary: some mix code statements and markup
directly (e.g. Cheetah), some embed code statements in special <%...%>
style tags (e.g. PSP), some hide all code within HTML tag attributes
(e.g. TAL, Kid), providing varying degrees of designer-friendliness as
a result.

3. DOM-style systems. This is a more recent arrival and a smaller
category. These systems completely separate markup from presentation
logic. Selected HTML elements are flagged using specific named tag
attributes (e.g. id="somename") or simple compiler directives, e.g.
(nevow:render="somename"); the template is then compiled into a simple
templating-oriented (i.e. not w3c) DOM, allowing these elements to be
manipulated programmatically by standard Python scripts. Very designer
and developer friendly, although less experienced programmers may find
the higher level of abstraction involved a bit offputting. Examples:
PyMeld, HTMLTemplate [1], Nevow.Render.
For a fairly extensive list of available systems, see
<http://wiki.python.org/moin/WebProgramming>. Unfortunately they're not
well categorised there, but I can't think of a better, up-to-date list
off the top of my head and most will provide decent overviews so it
shouldn't take too long to take a quick look at each.

Note that some templating engines are embedded into larger web
programming frameworks and may or may not be usable independently.
Conversely, some web frameworks may be coupled to a specific templating
system, while others allow you to choose your own.

HTH

has

--
[1] Disclaimer: I wrote HTMLTemplate. Also, shameless plug:
<http://freespace.virgin.net/hamish.sanderson/htmltemplate.html>

Nov 22 '05 #11
> No templates, no python-like or special languages, only pure and simple python.
You can embedd python into html or, if it better suits your programming
style, you can embed html into python. Why don't you give it a try?


I dislike embedding code or html in each other, apart from the
'impurity' of mixing code and user interface it makes them inseparable.

Using templates means that the code can work with different templates,
and this should be seamless, it also means that different code can be
used with the templates, for example if different languages are used.

The main advantage, for me, is that different outputs formats can be
created without changing the code. If the user wants a set of data in a
table then the html template is used, if they want a csv file of the
data, that is just a different template name. A printed report: same
code just a different template name. XML, simple text, postscript,
EDIFACT file, all done with same code, different template. Just arrange
for the name of the template file to be a parameter on the URL and the
various outputs can be selected by the user.

I did, however, write my own templating module, they are quite easy to
do.

Nov 22 '05 #12
> No templates, no python-like or special languages, only pure and simple python.
You can embedd python into html or, if it better suits your programming
style, you can embed html into python. Why don't you give it a try?


I dislike embedding code or html in each other, apart from the
'impurity' of mixing code and user interface it makes them inseparable.

Using templates means that the code can work with different templates,
and this should be seamless, it also means that different code can be
used with the templates, for example if different languages are used.

The main advantage, for me, is that different outputs formats can be
created without changing the code. If the user wants a set of data in a
table then the html template is used, if they want a csv file of the
data, that is just a different template name. A printed report: same
code just a different template name. XML, simple text, postscript,
EDIFACT file, all done with same code, different template. Just arrange
for the name of the template file to be a parameter on the URL and the
various outputs can be selected by the user.

I did, however, write my own templating module, they are quite easy to
do.

Nov 22 '05 #13
I meant that it is not strictly necessary to use templates in
Karrigell, although you can use Cheetah if you want.
I'm not used to templates mainly because I'm familiar with the way PHP
works and, for simple dynamic sites like those I work on, this is the
simpliest approach.
Another reason is that I'm a little bit lazy for learning yet another
language, be it a python-like one or a template one.

Also, I feel that Python is easy enough for having to resort to another
language.
I usually create my pages with Dreamweaver or any other visual tool,
and once the design is ready, I add a few python lines to it which,
combined with modules that are separated from the html code, work
wonders on my sites.

Nov 22 '05 #14
I meant that it is not strictly necessary to use templates in
Karrigell, although you can use Cheetah if you want.
I'm not used to templates mainly because I'm familiar with the way PHP
works and, for simple dynamic sites like those I work on, this is the
simpliest approach.
Another reason is that I'm a little bit lazy for learning yet another
language, be it a python-like one or a template one.

Also, I feel that Python is easy enough for having to resort to another
language.
I usually create my pages with Dreamweaver or any other visual tool,
and once the design is ready, I add a few python lines to it which,
combined with modules that are separated from the html code, work
wonders on my sites.

Nov 22 '05 #15
has
ri****@Azonic.co.nz wrote:
I dislike embedding code or html in each other, apart from the
'impurity' of mixing code and user interface it makes them inseparable.

Using templates means that the code can work with different templates,
and this should be seamless, it also means that different code can be
used with the templates, for example if different languages are used.


This seems to contradict your statement that you dislike 'embedding
code or html in each other', since the scenarios you describe still
involve embedding presentation logic in markup. (The only templating
systems that *completely* separate logic from markup are the DOM-style
ones.)

I assume what you really meant is that you don't like embedding *model*
logic in markup, which is generally good design practice. However,
templating systems that use Python for presentation logic (Karrigell,
PSP, Nevow, HTMLTemplate, etc) certainly don't force you to put model
logic into the template; you are quite entitled to keep that separate
as per MVC. They just don't *enforce* the model logic/presentation
logic separation as some authoritarian custom language-based systems
do.

HTH

Nov 22 '05 #16
has
ri****@Azonic.co.nz wrote:
I dislike embedding code or html in each other, apart from the
'impurity' of mixing code and user interface it makes them inseparable.

Using templates means that the code can work with different templates,
and this should be seamless, it also means that different code can be
used with the templates, for example if different languages are used.


This seems to contradict your statement that you dislike 'embedding
code or html in each other', since the scenarios you describe still
involve embedding presentation logic in markup. (The only templating
systems that *completely* separate logic from markup are the DOM-style
ones.)

I assume what you really meant is that you don't like embedding *model*
logic in markup, which is generally good design practice. However,
templating systems that use Python for presentation logic (Karrigell,
PSP, Nevow, HTMLTemplate, etc) certainly don't force you to put model
logic into the template; you are quite entitled to keep that separate
as per MVC. They just don't *enforce* the model logic/presentation
logic separation as some authoritarian custom language-based systems
do.

HTH

Nov 22 '05 #17
>> Using templates means that the code can work with different templates,
and this should be seamless, it also means that different code can be
used with the templates, for example if different languages are used.
This seems to contradict your statement that you dislike 'embedding
code or html in each other', since the scenarios you describe still
involve embedding presentation logic in markup. (The only templating
systems that *completely* separate logic from markup are the DOM-style
ones.)


Perhaps that is why I implemented my own mechanisms for templating. My
templates contain no logic at all and can be used from my Python
programs, Cobol or C equally well.

Contrarywise, my Python programs choose at runtime the required
template (depending on configuration, user request or other) and then
the same program code will output HTML, XML, EDIFACT, CSV, printed
report or other dependant entirely on the content of the template file.

Nov 22 '05 #18
>> Using templates means that the code can work with different templates,
and this should be seamless, it also means that different code can be
used with the templates, for example if different languages are used.
This seems to contradict your statement that you dislike 'embedding
code or html in each other', since the scenarios you describe still
involve embedding presentation logic in markup. (The only templating
systems that *completely* separate logic from markup are the DOM-style
ones.)


Perhaps that is why I implemented my own mechanisms for templating. My
templates contain no logic at all and can be used from my Python
programs, Cobol or C equally well.

Contrarywise, my Python programs choose at runtime the required
template (depending on configuration, user request or other) and then
the same program code will output HTML, XML, EDIFACT, CSV, printed
report or other dependant entirely on the content of the template file.

Nov 22 '05 #19

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

Similar topics

13
by: Michele Simionato | last post by:
What is the recommended way of generating HTML from Python? I know of HTMLGen and of few recipes in the Cookbook, but is there something which is more or less standard? Also, are there plans to...
14
by: Philippe C. Martin | last post by:
Hi, I wish to use an easy way to generate reports from wxPython and feel wxHtmlEasyPrinting could be a good solution. I now need to generate the HTML wxHtmlEasyPrinting can print: I need to...
8
by: John M. Gabriele | last post by:
I'm putting together a small site using Python and cgi. (I'm pretty new to this, but I've worked a little with JSP/servlets/Java before.) Almost all pages on the site will share some common...
0
by: pkassianidis | last post by:
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...
10
by: Sullivan WxPyQtKinter | last post by:
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...
15
by: lxyone | last post by:
Using a flat file containing table names, fields, values whats the best way of creating html pages? I want control over the html pages ie 1. layout 2. what data to show 3. what controls to...
5
by: jmDesktop | last post by:
Hi, I was using .net and it uses templates. I like that it did not mix the UI with logic. I saw there are many templating engines for php usage. Can you recommend one? I don' t know which to...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.