Re: modpython, apache and windows

Discussion in 'Python' started by Bob Van Zant, Jan 5, 2005.

  1. Bob Van Zant

    Bob Van Zant Guest

    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
    >
     
    Bob Van Zant, Jan 5, 2005
    #1
    1. Advertising

  2. Bob Van Zant

    Guest

    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
     
    , Jan 5, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?q?Lorenz_K=F6hl?=

    modpython compilation error

    =?iso-8859-1?q?Lorenz_K=F6hl?=, Aug 29, 2003, in forum: Python
    Replies:
    0
    Views:
    357
    =?iso-8859-1?q?Lorenz_K=F6hl?=
    Aug 29, 2003
  2. Julio C?sar Carrascal

    ModPython and embedding

    Julio C?sar Carrascal, Nov 13, 2003, in forum: Python
    Replies:
    0
    Views:
    288
    Julio C?sar Carrascal
    Nov 13, 2003
  3. Sam
    Replies:
    2
    Views:
    333
    Steve Holden
    Jan 5, 2005
  4. Wensheng

    egg and modpython

    Wensheng, Sep 8, 2006, in forum: Python
    Replies:
    8
    Views:
    433
    Paul Boddie
    Sep 13, 2006
  5. Andrus
    Replies:
    0
    Views:
    221
    Andrus
    Jun 18, 2008
Loading...

Share This Page