[mod_python] How can I have sensible URLs?

Peter Bittner peter.bittner at gmx.net
Wed Sep 4 17:56:13 EST 2002


Hi!

> "Grisha" wrote:
> > 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.)

I have adapted my publisher.py so that is now takes a "default()" method by
default 
if no one is specified in the URL. (See the the code below.)

Do you think this adaption is worth being part of the "official" mod_python?
Anyone 
who finds this interesting? (Anyone who wouldn't like it?)

> 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 was a little bit unprecise: It is not a 404 that is raised, it is a
"IndexError: 
string index out of range" that is displayed.

I have changed the code in "publisher.py" from

80:    if func_path[-1] == ".":
81:        func_path = func_path[:-1]

to the following: (the numbers on the left are the line numbers)

80:    if func_path == "":          # set method name to "default"
81:        func_path = "default"    # if none is specified in the URL
82:    elif func_path[-1] == ".":
83:        func_path = func_path[:-1]

(Actually, now it displays the 404 if no "default" method is present! ;-)
*argl*)

Now I have a default-method in each script and I can call scripts by 
"http://servername/scriptname/". It works! :-)

Please send me your comments about this change. Does anyone feel this should
be a 
default mod_python behavior? (I don't like to know my mod_python code only
works on 
my very own server and nowhere else, hugh!)

Cheers,
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.
http://www.gmx.net
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 81 bytes
Desc: not available
Url : http://mailman.modpython.org/pipermail/mod_python/attachments/20020904/8932dce9/attachment-0003.obj


More information about the Mod_python mailing list