Take the 2-minute tour ×

quick question: I have created a web server using CherryPy. It requires authentication for all pages, so my default handler returns the login page object. Due to the way that CherryPy handles the dispatches, somebody who requests:


would be redirected to:


however, I'd like all unauthenticated requests to be invoked from the root level, independent of the potential additional parameters added in the HTML request, e.G.:

localhost:80/a/b/c --> localhost:80/login

Currently I am solving this by returning a HTML based redirect:

'<meta http-equiv="REFRESH" content="0;url=/login">'

I feel this is a very unclean solution and would rather want to use a CherryPy based solution. I looked at cherrypy.HTTPRedirect and cherrypy.url, but I haven't found a way to make them work for this problem.

Any thoughts?

Thank you!

share|improve this question

1 Answer 1

up vote 13 down vote accepted

You can specify the login page with a redirect: raise cherrypy.HTTPRedirect("/auth/login")

But, take a look here, there is a sample of how to write an authentication routine:


There is also an example of how to redirect the user back at the requested page after login.

share|improve this answer
that did actually do the trick. I somehow didn't expect that the "raise" was needed here, but it doesn't work without it and including it makes for a much cleaner solution. Thanks –  Muppet Aug 19 '12 at 23:22

Your Answer


