Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

Python 2 is no longer supported by the community. We recommend that you migrate Python 2 apps to Python 3.

Login URLs

Stay organized with collections Save and categorize content based on your preferences.

The Users API provides functions for constructing URLs that allow the user to sign in or sign out, then be redirected back to your application.

users.create_login_url() and users.create_logout_url() each take a destination URL for the application, and return a URL for signing in or signing out that redirects back to the given URL afterward.

class MainPage(webapp2.RequestHandler):
    def get(self):
        user = users.get_current_user()
        if user:
            nickname = user.nickname()
            logout_url = users.create_logout_url('/')
            greeting = 'Welcome, {}! (<a href="{}">sign out</a>)'.format(
                nickname, logout_url)
            login_url = users.create_login_url('/')
            greeting = '<a href="{}">Sign in</a>'.format(login_url)

The development web server simulates Google Accounts using its own sign-in and sign-out facilities. When you sign in to your application on the development web server, the server prompts you for an email address to use for the session. See The Development Web Server for more information.

Tip: An easy way to restrict access to a part of your application to signed in users is to use the login: required configuration element for the URL handler. See Configuring an App.