473,221 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,221 software developers and data experts.

Page layouts in mod_python?

Hey everyone,

Is it possible to automatically insert headers/footers using
mod_python?
I will be not be using PSP's, so I cannot use the PSP/include solution.
Furthermore, the header will be dynamic; it won't be a static HTML
page.

In short, I've been looking for a page layout facility using
mod_python.
(Similar to the layout capability in Ruby on Rails.)

Thank you in advance,
-Michael

Dec 19 '06 #1
3 1772
Michael a écrit :
Hey everyone,

Is it possible to automatically insert headers/footers using
mod_python?
I will be not be using PSP's, so I cannot use the PSP/include solution.
Furthermore, the header will be dynamic; it won't be a static HTML
page.

In short, I've been looking for a page layout facility using
mod_python.
(Similar to the layout capability in Ruby on Rails.)
mod_python is mainly a librairy exposing the apache API to Python - not
a full-stack db-to-web framework. What you want here is a HTML
templating system. There are quite a lot available in Python - look for
SimpleTAL, Genshi, Myghty, Jinja, Cheetah, etc...

HTH
Dec 19 '06 #2

Bruno Desthuilliers wrote:
Michael a écrit :
Hey everyone,

Is it possible to automatically insert headers/footers using
mod_python?
I will be not be using PSP's, so I cannot use the PSP/include solution.
Furthermore, the header will be dynamic; it won't be a static HTML
page.

In short, I've been looking for a page layout facility using
mod_python.
(Similar to the layout capability in Ruby on Rails.)

mod_python is mainly a librairy exposing the apache API to Python - not
a full-stack db-to-web framework. What you want here is a HTML
templating system. There are quite a lot available in Python - look for
SimpleTAL, Genshi, Myghty, Jinja, Cheetah, etc...
Contrary to the above advise, you could actually use mod_python to do
what you want and you do not need a full stack to do it. Whether you
would want to use just mod_python is another question and the answer
would depend on a bit on what form the HTML files you want to modify
are in or what is generating them.

The first option available is to write an Apache output filter using
mod_python which takes the content of the page and searches for the
<bodyand </bodytags and inserts at those points the appropriate
header/footer. Using this scheme, because you are looking for tags
already within the HTML page, you do not need to modify the original
HTML source files. Because it is an output filter, the technique will
work on both static files and on files which have been generated
dynamically by PHP, mod_perl, mod_python or any other Apache response
handler capable of generating dynamic pages.

For this first technique, you do not even have to use mod_python if you
didn't want to, as there are other Apache modules which have been
designed to specifically use this technique to insert headers and
footers in pages. These other modules are written in C and so are
probably going to be quicker as well as more flexible without you
having to do too much hard work.

The second option, although not strictly mod_python specific, is to
enable server side include processing for HTML files. For this to work
you would need to modify the original HTML source files or what is
generating them to add in appropriate SSI directives to include the
header/footer. Again, because SSI is performed as an output filter,
source files can be static or dynamically generated.

If using basic SSI, the include of the header/footer to get dynamic
information would be done as a virtual include. That is, it generates
an Apache subrequest to a handler which generates the header/footer.
This handler could be implemented as a CGI script, mod_python handler,
mod_perl handler or even PHP.

Alternatively, in mod_python 3.3 (soon to be released), one can use the
new ability to use Python code in conjunction with SSI. For dynamic
header/footer snippets, this would involve adding callouts to pages to
Python code setup using mod_python.

For an example of header/footer generation using Python code, see:
http://www.dscpl.com.au/wiki/ModPyth...erSideIncludes

If you particularly want to use mod_python, for further discussion on
this topic and what may be best for what you want to do, I would
suggest you might take the conversation over to the mod_python user
mailing list. Details for the list are on the mod_python web site.

Graham

Dec 19 '06 #3
Graham Dumpleton a écrit :
Bruno Desthuilliers wrote:
>>Michael a écrit :
>>>Hey everyone,

Is it possible to automatically insert headers/footers using
mod_python?
I will be not be using PSP's, so I cannot use the PSP/include solution.
Furthermore, the header will be dynamic; it won't be a static HTML
page.

In short, I've been looking for a page layout facility using
mod_python.
(Similar to the layout capability in Ruby on Rails.)

mod_python is mainly a librairy exposing the apache API to Python - not
a full-stack db-to-web framework. What you want here is a HTML
templating system. There are quite a lot available in Python - look for
SimpleTAL, Genshi, Myghty, Jinja, Cheetah, etc...


Contrary to the above advise, you could actually use mod_python to do
what you want and you do not need a full stack to do it.
I never said the OP would need a full-stack framework - just that there
are existing solutions that can solve the problem in a very simple way.
Dec 20 '06 #4

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

Similar topics

1
by: wolf | last post by:
i would like to briefly share my experiences with installing mod_python on a w2000 box. i must say that i believe the installation process to be unnecessarily complicated by the simple fact that...
6
by: Karl A. Krueger | last post by:
I'm in the middle of refactoring a small mod_python Web application, which uses the Publisher handler. This application is currently a single main Python file (which loads several other files as...
2
by: Robert J. Hansen | last post by:
I'm not entirely certain comp.lang.python is the proper newsgroup for mod_python questions, but "comp.lang.python.web" doesn't seem to exist, so... my apologies in advance if this is considered...
0
by: Python_it | last post by:
I'm going to work with mod_python. I install mod_python 3.2.2b for python 2.4. If i test my install with mptest.py see this link:...
6
by: Anthony L. | last post by:
I am writing a web application that is comparable to a content management system used in blogging. I really want to use Python after having done some evaluation coding using Python 2.3.5 with...
1
by: treelife | last post by:
I'm getting and internal server error when | run the following mod_python script. I am actually trying to run Django. Script: from mod_python import apache def handler(req):...
6
by: Gleb Rybkin | last post by:
when running apache, mod_python in windows. This looks pretty strange. Creating a simple python file that shows current time will correctly display the time in apache the first time, but freezes...
4
by: james00 | last post by:
Switching Page Layouts!!! Does anyone have any idea how to create a script for Switching Page Layouts. I know how to create one for Style Sheet Switcher ...
1
by: braneof | last post by:
I'm not sure if this belongs here or in the apache area, but any help would be appreciated. I developed a web survey in python cgi on my home computer using Apache2Triad, and it works. I tried just...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...

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.