Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: modpython, apache and windows

Reply
Thread Tools

Re: modpython, apache and windows

 
 
Bob Van Zant
Guest
Posts: n/a
 
      01-05-2005
Fortunately most of the Python-for-the-web implementations do not follow
closely to the PHP paradigm of web-based programming. There are some,
like PSP, that more closely model what PHP does.

It is not uncommon to have something like index.py which does hardly
anything except fire up a framework that takes care of parsing the rest
of the URI and passing control over to the proper script. Using some
relatively cryptic features of Apache you can hide the fact that
everything goes through index.py (mod_rewrite).

You might be interested in the Aquarium web framework
(http://aquarium.sf.net). It provides a very flexible, mature framework
for developing web applications including a session manager, a form
validation library and a form generation "widget" among many other
things. The documentation on the official aquarium site is fairly
cryptic but I have written a few more intro documents at
http://bob.norcalttora.com including an example excerpt of an httpd.conf
file that will configure mod_python to work with Aquarium including the
previously mentioned apache rewrite rules.

I have never tried to get this working in windows but if you get it
working I'd be very interested in seeing what changes you had to make.
I'm willing to help you along the way.

Not really sure how else to help you at this point. The index.py that
you had working was probably on the right track.

-Bob


On Wed, 2005-01-05 at 01:12 +0000, Sam wrote:
> Hi All,
>
> I am interested in learning python since I am hearing more and more
> about python for use in web development
>
> I am starting out on python, with knowledge of PHP some perl
>
> my current hurdle is setting up either apache 1 or 2 with python 2.3.3 I
> have installed modpython fine
>
> which informed me that I need to make some configuration changes to
> httpd.conf
>
> I have not had it working yet, searches on the web give conflicting
> suggestions and so far has confused me
>
> some forums mention spyce and serving .spy files
>
> so far I one explanation worked in that a .py file was parsed but I had
> to set the name of the actual file within apache.conf
> this seems strange
>
> thanks in advance >> SS
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.298 / Virus Database: 265.6.7 - Release Date: 30/12/2004
>


 
Reply With Quote
 
 
 
 
grahamd@dscpl.com.au
Guest
Posts: n/a
 
      01-05-2005
Bob Van Zant wrote:
> Fortunately most of the Python-for-the-web implementations do not

follow
> closely to the PHP paradigm of web-based programming. There are some,
> like PSP, that more closely model what PHP does.
>
> It is not uncommon to have something like index.py which does hardly
> anything except fire up a framework that takes care of parsing the

rest
> of the URI and passing control over to the proper script. Using some
> relatively cryptic features of Apache you can hide the fact that
> everything goes through index.py (mod_rewrite).


I have never really liked how all these different mod_python extensions
insist on using their own special file extensions, eg., .psp, .mps etc.
All it does is to expose what you are using to implement a site and
makes it hard for you to convert to a different implementation
mechanism as all your URLs then need to change.

As you point out, the only way around it is to use mod_rewrite rules.
Overall, from what I have seen all it does is make configuration files
harder to understand and spawn lots of newbie questions as to why
they can't get anything to work.

To me it is more sensible to use REST principles and not use file type
extensions at all, or use an extension which reflects the type of
content being delivered up and not the mechanism used to generate it.

FWIW, the Vampire package tries to address this problem in
mod_python by providing a simple mechanism as an extension to
mod_python which gives one greater control over the file extension
used in a URL and what handler that then maps to.

To set it up, one has a single directive in your httpd.conf or htaccess
file of the form:

PythonHandler vampire

You can then place in your directory any number of content handler .py
files. Eg. you might have index.py, about.py, report.py etc. In the
first instance, no matter what the file type extension on the URL, if
the
basename in the URL request matches the basename of the content
handler file, then it is that file which is the target of the request.

Thus, if you used the following URLs, they would map as shown:

index.html --> index.py
about.html --> about.py
report.pdf --> report.py
report.csv --> report.py
feedback --> feedback.py

Now normally the content handler would be called "handler()". Using
vampire though, you extend the name with the file type, thus:

index.html --> will call handler_html() in index.py
about.html --> will call handler_html() in about.py
report.pdf --> will call handler_pdf() in report.py
report.csv --> will call handler_csv() in report.py
feedback --> will call handler() in feedback.py

Thus, you can use a more sensible file type in the URL without having
to resort to mod_rewrite rules. Further, where a specific resource can
be represented in multiple formats which are both generated on the
fly, you can have a handler for each in the same content handler .py
file, eg., as in .pdf and .csv case. You can also follow REST
princinples
and have no extension at all.

You aren't restricted to just having content handlers in a directory
though. You can still have other files such .html and .jpg files. If
Vampire determines that there is no content handler corresponding to
a request, it will decline to service it and pass it back to Apache
which
will then serve up the raw .html or .jpg file directly.

I should point out that Vampire is not a framework in the sense that
it doesn't dictate how your pages are rendered. That handler function
which is called is basically the same as a stock standard mod_python
handler method. Inside that function you still need to provide the code
which creates the response, although there is no reason why you can't
on a per resource case trigger off a different system such as PSP,
mpservlets or HTMLTemplate to generate the HTML.

More could be said, but best to check out:
http://www.dscpl.com.au/projects/vampire

--
Graham Dumpleton

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems running Apache FOP: org.apache.fop.fo.FOTreeBuilder fatalError Pablo Java 0 03-28-2007 02:31 PM
org/apache/xpath/objects/XObject incompatible with org/apache/xpath/objects/XNodeSet duduch_1er@hotmail.com XML 4 08-10-2006 01:38 PM
Apache FileUpload - java.lang.NoClassDefFoundError: org/apache/commons/io/FileCleaner kebabkongen@hotmail.com Java 2 03-16-2006 09:20 AM
AXIS jars org.apache.axis.wsi.* and org.apache.axis.transport.jms.* unkwb@web.de Java 0 02-23-2005 04:02 PM
How to test speed difference of Perl/Apache and SSI/Apache The Poor Perl Misc 2 09-27-2003 12:26 PM



Advertisments