views:

53

answers:

1

I have a tool hook setup for 'before_finalize' like so:

def before_finalize():
    d = cherrypy.response.body
    location = '%s/views' % cherrypy.request.app.config['/']['application_path']
    cherrypy.response.body = Template(file='%s/index.tmpl' % location).respond()

What I need to do is find out inside that hook what route (I'm using RoutesDispatcher) got us to that hook, or what the URI is, so I can appropriately find my template based on that. How can I find this information?

A: 

cherrypy.url will get you the complete URI, but I suspect that's not quite what you're looking for...why do you need it? If you're trying to form your 'location' variable based on the URI, you probably want path_info instead of the complete URI:

location = '%s/views' % request.app.config['/']['application_path']
if request.path_info.endswith('/'):
    fname = '%s%sindex.html' % (location, request.path_info)
else:
    fname = '%s%s.html' % (location, request.path_info)
fumanchu