Python 2.7 has reached end of support and will be deprecated on January 31, 2026. After deprecation, you won't be able to deploy Python 2.7 applications, even if your organization previously used an organization policy to re-enable deployments of legacy runtimes. Your existing Python 2.7 applications will continue to run and receive traffic after their deprecation date. We recommend that you migrate to the latest supported version of Python.

Login URLs

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.

classMainPage(webapp2.RequestHandler):
 defget(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)
 else:
 login_url = users.create_login_url('/')
 greeting = '<a href="{}">Sign in</a>'.format(login_url)
 self.response.write(
 '<html><body>{}</body></html>'.format(greeting))

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.

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025年12月17日 UTC.