I have found a solution to make internal requests. All that is required to
allow for an internal request to work without issues is to copy the current
request environment to the new internal request. My solution is shown
below.
from wsgiref.simple_server import make_server
from tg import expose, TGController, AppConfig
from tg import response, request
from webob import Request
class RootController(TGController):
@expose()
def index(self):
return "<h1>Hello World</h1>"
@expose()
def test(self):
from webob.request import Request, environ_from_url
# Try to route internally
r = 'http://localhost:8080/index'
req = Request.blank('/') #create new request
req.environ.update(request.environ) #set the current request
environment to the new request
req.environ.update(environ_from_url(r)) #set the path for the
environment
resp = req.get_response(wsgi_app) #make request
tg.response.headers['content-type'] = 'text/xml'
return resp.body
config = AppConfig(minimal=True, root_controller=RootController())
print "Serving on port 8080..."
wsgi_app = config.make_wsgi_app()
httpd = make_server('', 8080, wsgi_app)
httpd.serve_forever()
Cheers
- Chris
--
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/turbogears.
For more options, visit https://groups.google.com/d/optout.