Index function and sub resources

6 views
Skip to first unread message

Voltron

unread,
Jun 20, 2009, 9:05:06 AM6/20/09
to cherrypy-users
I am trying to conditonally return a resource from the index page. I
noticed that any other URL results in a 404:


# Snippet

@cherrypy.expose

class User:
def index(self, id = none):
if id:
...
else:
return "User not found"


So calls to /user work, but calls like "user/2" fail. Does the index()
function behave differently?


Thanks

Voltron

unread,
Jun 20, 2009, 9:46:26 AM6/20/09
to cherrypy-users
I just noticed that calls like:

"user?ide=2" work, is this a bug?

Thanks

Voltron

unread,
Jun 20, 2009, 10:27:30 AM6/20/09
to cherrypy-users
After a little more researching, I moved the sub resource variable to
the "default()" handler, now it works as expected. Is this correct way
to handle this problem? I did not find any documentation on this.

Thanks

fumanchu

unread,
Jun 20, 2009, 11:09:17 AM6/20/09
to cherrypy-users
Yes, the index method does behave differently. It is the only function
which cannot take positional arguments. This is mentioned indirectly
in http://www.cherrypy.org/wiki/CherryPyTutorial#Partialmatchesandthedefaultmethod
-- could use better docs.


Robert Brewer
fuma...@aminus.org
Reply all
Reply to author
Forward
0 new messages