473,416 Members | 1,732 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,416 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 1783
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...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.