Monday, August 1, 2011

Mod_Python: "internal_redirect" tricks

1. Access the request object from which it was redirected by req.prev, cause Apache/Mod_Python constructs a new request object when handling an internal_redirect() call.
2. Pass information through req.internal_redirect(), for example, a handler which contains:
import os 
def handler(req): 
    return apache.OK
And a second handler which is triggered as the target of the redirect which contains:
from mod_python import apache 
def handler(req): 
    req.content_type = "text/plain" 
    for key in req.subprocess_env.keys(): 
        print >> req, key, "=", req.subprocess_env[key] 
    return apache.OK

No comments:

Post a Comment