[mod_python] How can I have sensible URLs?

Peter Bittner peter.bittner at gmx.net
Wed Sep 4 11:03:01 EST 2002

Hi Grisha,

> Basically, the publisher doesn't have a "default" method name. (There is
> no particular reason for this, it just didn't occur to me at the time of
> writing.)

Wouldn't it be a nice idea to provide such a default method name? ("main"
seems a good name for that task.)

I am very keen on organizing my web projects nicely, so I usually structure
the application using separate file for separate tasks.

I also like to obey a couple of web-design paradigmas such as "let your URLs
be hackable", which says nothing less than when the user modifies the URL
there shouldn't be an "unexpected behaviour" as a result. I do get a little of
a headache when I think of users removing the "/dothis" from a
"http://www.mydomain.com/myscript/dothis" and then getting a "404 Not Found".  :-(

I have the feeling that this is really a point that presents a huge
understanding problem to novices, to mod_python beginners, (even if they are
perfectly familiar to Python).
Python scripts begin a the start of the file, everything is processed
sequentially. Why not having a default starting point for mod_python scripts?

Grisha, what was/is your motivation to omit the ".py" in the URL at the end
of the script's filename? - Don't get me wrong, I do see the beauty in this
solution (since the ".py" hits the eye), but isn't this arguably? Wouldn't a
CGI-style processing ("..../myscript.cgi?opt1=abc") be more straight forward?

I would be really happy seeing mod_python to be that easy to understand and
easy to use (to write applications) that it might be a real alternative to
PHP, JSP and ASP, and still (with Python a its base) being a language where
beautiful and well structured code emerges from.

> There is probably more than one way to accomplish something to that
> extent, one way would be to try a redirect, something like:
> Redirect /index.py http://www.mydomain.com/index.py/index

Apache's module mod_rewrite might be some kind of workaround to this. But is
this really satisfying? How do other programmers feel about this?

Cheers, Peter

> On Tue, 3 Sep 2002, Peter Bittner wrote:
> > Hi there!
> >
> > I have a little bit of understand problem of how the architecture of a
> > mod_python web application (say web site, if you want) should be.
> >
> > I would like to have the URLs as if the mod_python scripts were simply
> some
> > kind of "special HTML documents", comparable to PHP scripts.
> >
> > For example, I have written a script named "index.py" which is located
> on my
> > document root. So I would expect "http://www.mydomain.com/index.py" to
> > execute my script (I have set up my Apache so that I can omit the
> filename, too).
> > But it doesn't. When I remove the ".py" at the end there is no change to
> this
> > too.
> >
> > So what I have to do is to execute
> "http://www.mydomain.com/index/method",
> > provided a method called "method" in my script. This way it works. - But
> is
> > there a way to have "HTML-like" or "PHP-like" behavior? Or how do I have
> to
> > organize my scripts so that I can have my whole website written in
> mod_python
> > and can run it with "http://www.mydomain.com" alone?
> >
> > Does anyone have a good example about how to do this?
> >
> > Thanks in advance!
> > Peter
> >
> > --
> > Peter Bittner
> > mobil: +43/(0)650/4151545
> > web: http://www.bittner.at.tf - http://beam.to/htmlkurs
> > mail: peter.bittner at gmx.net
> >
> > "Free software is like free speech, not free beer" (Richard Stallman)

GMX - Die Kommunikationsplattform im Internet.

More information about the Mod_python mailing list