[mod_python] Getting request object

Radek Bartoň blackhex at post.cz
Mon Dec 5 17:12:31 EST 2005


Hello.
I like using mod_python's mod_python.publisher like this:

class MyClass:
  def __init__(self):
    # can I get request object here?
    ...
  def __str__(self):
    ...
  def method1(self, req):
    ...
  def method2(self, req):
    ...

# or can I get request object here and pass it to MyClass's constructor?
index = MyClass():
...

instead of classic usage:

....
def index(req)
   instance = MyClass()
   ....

because you can access each class method by typing URL (i. e. 
http://hostname/file/index/method1) or you can access object itself (i. e. 
http://hostname/file). The problem is that when you use second way you can't 
pass request object in class's constructor. Is there any posibility how to 
get request object in class's constructor or in global scope?


More information about the Mod_python mailing list