App Engine Python Authentication Custom Redirect
Question: 
    handlers:
    - url: /secure_api/.*
      script: _go_app
      login: required
      auth_fail_action: unauthorized
    

This code only brings me to a page saying "Login required to view page." Is
there a way to instead redirect to my home page?


Answer: When you specify `auth_fail_action: unauthorized`, you get the page you are
seeing (see
[here](https://developers.google.com/appengine/docs/python/config/appconfig#Requiring_Login_or_Administrator_Status)
for the details). Changing `unauthorized` to `redirect` will take them to the
login screen, but if you want to do more granular handling of users based on
their logged-in status, your best bet is to do it inside of your code via the
`Users` API. For instance (this is adapted from the
[docs](https://developers.google.com/appengine/docs/python/users/)), here is a
simple example that would redirect a non-logged-in user to `/`:

    
    
    from google.appengine.api import users
    import webapp2
    
    class MyHandler(webapp2.RequestHandler):
        def get(self):
            user = users.get_current_user()
            if user:
                # Do stuff here for logged-in users
            else:
                # Redirect if user is None, which is the case for non-logged-in users
                self.redirect('/')
    

