generating method names 'dynamically'
Peter Hansen
peter at engcorp.com
Thu Jan 26 22:50:31 EST 2006
Daniel Nogradi wrote:
> Well, I would normally do what you suggest, using parameters, but in
> the example at hand I have to have the method names as variables and
> the reason is that the whole thing will be run by apache using
> mod_python and the publisher handler. There a URL
> http://something.com/program2/Bob is mapped to the 'Bob' method of the
> file program2.py and I want to be able to have URL's with different
> names. I know I can solve this problem with parameters and functions
> and using the GET http method, but I would like to have pretty URL's
> without & and ? signs. I didn't want to ask this on the mod_python
> list because after all it's a pure python question.
Although I see Michael's answer suits you, there is another option that
might be simpler, depending on your situation. Use a Rewrite rule of
some kind in the Apache configuration to turn the URL with ".../Bob"
into a URL with "...&name=Bob". That way this remapping is completely
outside of your code and you don't complicate the Python side just
because of the need to make the URLs user-friendly.
I realize this could be impractical depending on how much control you
have over the web server configuration, your knowledge level with
Apache, etc... just a suggestion.
Cheers,
-Peter
More information about the Python-list
mailing list