bottle hooks with beaker session middleware and checking logins
===

I'm writing a bottle application with beaker session middleware.

My code is has this:

      
    @bottle.route('/')
    def slash():
    
      try:
        beaker_session = request.environ['beaker.session']
      except:
        #redirect('/login')
        abort(401, "Failed beaker_session in slash")
    
      try:
        name = beaker_session['name']
      except:
        redirect('/login')

for each route request except /login. I know there is a bottle hook system to do things before requests, but  I'm not sure how best to use it to check if someone is logged in or not.

I'm fairly new to python webapps using bottle. Not to many people are using it with beaker session middleware so I don't have a lot of examples to go by.

Thanks for any help or pointers!