CherryPy Custom Tool for user authentication
问题 I'm trying to set up a simple way of decorating methods in my CherryPy controller classes so that a user is redirected to the login page if they haven't authenticated yet. I was going to do a basic Python decorator, but an answer here suggested I use a CherryPy Custom Tool instead. So I'm trying to do that, but I can't get it to work. Here's what I have: def authenticate(): user = cherrypy.session.get('user', None) if not user: raise cherrypy.HTTPRedirect('/?errMsg=Please%20log%20in%20first')