HTML Templates (Sitemesh/Tiles concept) in Python

S

Suren

Hello,

I am a newbie to python and web development. I am part of a fairly
simple project and we are trying to identify an efficient way to design
our html pages. The technologies at our disposal are javascript, html
and python for now.

Our pages bear a very standard look. Here is what it looks like.

--------------------------------------------------
BANNER
--------------------------------------------------
| -l1 | <- -> Logout
| -l2 |---------------------------------------
| -l3 |
| -l4 | CONTENT
| -l5 |---------------------------------------
| | COPYRIGHT
-------------------------------------------------

l1 through l5 are links that basically target the content page and fill
in. Each page via that link has a python reference to go gather
appropriate data for the content page. We are using frames to do the
banner.html, menu.html (the links page) and the content page.

For the content page, how can we decorate it on top with the back/front
buttons and logout buttons and botton with a copyright in every page.
It seems error prone as well as bad design to scatter this logic in
each content page. Is there a template logic like Sitemesh or Tiles
concept that can decorate a desired page just before show time?

Any other tips to help life easier are appreciated.
 
B

Bruno Desthuilliers

Suren said:
Hello,

I am a newbie to python and web development. I am part of a fairly
simple project and we are trying to identify an efficient way to design
our html pages. The technologies at our disposal are javascript, html
and python for now.

Python with ? CGI ? FastCGI ? mod_python ? Other ?

Our pages bear a very standard look. Here is what it looks like.
(snip)

l1 through l5 are links that basically target the content page and fill
in. Each page via that link has a python reference to go gather
appropriate data for the content page. We are using frames to do the
banner.html, menu.html (the links page) and the content page.

You shouldn't - unless this is an internal web-based application, not a
public site. Since your dynamically generating the pages, there's no
gain using frames - but there are huge drawbacks, for the programmers as
well as for the visitors.
For the content page, how can we decorate it on top with the back/front
buttons and logout buttons and botton with a copyright in every page.
It seems error prone as well as bad design to scatter this logic in
each content page. Is there a template logic like Sitemesh or Tiles
concept that can decorate a desired page just before show time?

There are lot of web templating engines in Python, and most of them
provide some way to either "extend" an existing template (to fill-in
page-specific stuffs) or to do server-side-includes-like inclusion of
common parts. Google for Genshi, Jinja, SimpleTAL, Mighty, Cheetah...
Any other tips to help life easier are appreciated.

Have you considered using one of the existing python web development
libraries/frameworks? Like Pylons, Turbogears, Django, Spyce, Karigell,
etc, etc, etc, etc...

My 2 cents...
 
S

Suren

Python with ? CGI ? FastCGI ? mod_python ? Other ?

We are using mod_python and SSI. We are inheriting some legacy code
that we do not want to mess with at all.
You shouldn't - unless this is an internal web-based application, not a
public site. Since your dynamically generating the pages, there's no
gain using frames - but there are huge drawbacks, for the programmers as
well as for the visitors.

Although not an internal site, this site is going to be in a controlled
environment. Only a handful of people may access the website.
There are lot of web templating engines in Python, and most of them
provide some way to either "extend" an existing template (to fill-in
page-specific stuffs) or to do server-side-includes-like inclusion of
common parts. Google for Genshi, Jinja, SimpleTAL, Mighty, Cheetah...

I will look at these and see it works.
Have you considered using one of the existing python web development
libraries/frameworks? Like Pylons, Turbogears, Django, Spyce, Karigell,
etc, etc, etc, etc...

My 2 cents...

We have not considered a framework coz the legacy code base has not
included one. We are living in the same source structure and did not
want to introduce a newer dependency. I hope we can find a
non-intrusive library/framework that does its job.


Thanks.
 
B

bruno de chez modulix en face

Suren a écrit :
We are using mod_python and SSI.

We are inheriting some legacy code
that we do not want to mess with at all.
Ok.


Although not an internal site, this site is going to be in a controlled
environment. Only a handful of people may access the website.

So the drawbacks of frames may not be a definitive show-stopper.
Anyway, and unless going thru useless complications, frames still have
at least 2 big problems : you cannot bookmark pages, and you cannot be
sure the use will see the effective content thru the "framed" page.
The main use case for frames is (was ?) to avoid duplicating the same
set of common elements (menus, header, footer etc) on each and evry
page of a site. With dynamic page generation and template systems, this
is no more a problem, so I see very few reasons to still use them.

(snip)
We have not considered a framework coz the legacy code base has not
included one. We are living in the same source structure and did not
want to introduce a newer dependency. I hope we can find a
non-intrusive library/framework that does its job.

Hard to tell what would be more appropriate without knowledge of the
existing code base and architecture... Anyway, both Jinja and Genshi
are relatively easy to setup and get started with. Mighty is a much
more complex and powerful beast (it's almost a whole web-components
framework by itsef).

My 2 cents
 
G

grahamd

Suren said:
We are using mod_python and SSI. We are inheriting some legacy code
that we do not want to mess with at all.

If you are already using SSI for basic page composition using 'include
virtual', it may be of interest for you to know that upcoming
mod_python 3.3 supports use of Python code directly with SSI. For
details see:


http://www.dscpl.com.au/wiki/ModPython/Articles/BasicsOfServerSideIncludes

To use this feature now, you would have to use latest mod_python code
base out of Subversion repository though. We are just tidying up last
few issues for 3.3, so code is more than usable at this point.

There is an example in the article about how the new feature can be
used for adding header, footers etc.

Graham
 
M

metaperl

Suren wrote:

It seems error prone as well as bad design to scatter this logic in
each content page. Is there a template logic like Sitemesh or Tiles
concept that can decorate a desired page just before show time?

Suren, you are looking for push-style templating. I list a number of
alternatives here:
http://www.livingcosmos.org/Members/sundevil/software-engineering/push-style-templating-systems/view

I use meld3 personally, but Templess looks pretty good and Webstring
also. Depends on your tastes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top