CherryPy redirects to root

quick question: I created a web server using CherryPy. It requires authentication for all pages, so my default handler returns the login page object. Due to CherryPy handling mailings, someone who asks for:

localhost:80/a/b/c 

will be redirected to:

 localhost:80/a/b/login 

however, I would like all unauthenticated requests to be invoked from the root level, regardless of the potential additional parameters added in the HTML, eG request:

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

I am currently solving this by returning an HTML based redirect:

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

I think 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 did not find a way to make them work for this problem.

Any thoughts?

Thanks!

+7
source share
1 answer

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

But, look here, there is an example of how to write an authentication procedure:

http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions

There is also an example of redirecting a user to the requested page after logging in.

+21
source

All Articles