Accessing the tree root from a class not in the main file

1 view
Skip to first unread message

metaperl

unread,
Mar 17, 2007, 1:45:54 AM3/17/07
to cherrypy-users
an internal redirect got me over this hump, but how could I have
called the method via the mounted tree?

def login_proc(self, username = None, password = None):
if username and password:
# Greet the user!
#return cherrypy.tree.mount_points['/'].data_entry.index()
raise cherrypy.InternalRedirect('/data_entry')
else:
return 'Please enter username/password <a href="./">here</
a>.'
login_proc.exposed=True

Robert Brewer

unread,
Mar 17, 2007, 11:40:16 AM3/17/07
to cherryp...@googlegroups.com

Well, you really don't want to do that. But if you did, it would be something like this in CherryPy 3:

return cherrypy.tree.apps['/'].root.data_entry.index()

What you have looks like it should work in CP 2.

But you don't want to do that anyway, because your boss is going to come in tomorrow and say, "let's move the whole app from '/' to '/department/apps'." And you'll have to rewrite your source code. :/ A more portable solution (in CP 3) would be:

return cherrypy.request.app.root.data_entry.index()

If for some odd reason you still want to know the actual mount point of the current app, that's available in cherrypy.request.script_name (again, in CP 3).


Robert Brewer
System Architect
Amor Ministries
fuma...@amor.org

winmail.dat
Reply all
Reply to author
Forward
0 new messages