google.appengine.ext.webapp.util package provides the following functions:
A Python annotation for webapp request handler methods that verifies that the user is signed in with a Google account, and redirects the user to the sign-in page if not signed in. The sign-in page redirects back to the request URL.
This annotation only works for GET requests.
from google.appengine.api import users from google.appengine.ext import webapp from google.appengine.ext.webapp.util import login_required class MyHandler(webapp.RequestHandler): @login_required def get(self): user = users.get_current_user() self.response.out.write('Hello, ' + user.nickname())
Runs a WSGI application in App Engine's CGI environment. This is comparable to using a WSGI-to-CGI adaptor such as the one provided by the
wsgirefmodule of the Python standard library, but has several advantages: run_wsgi_app() automatically detects whether the application is running in the development server, and if so outputs errors to the browser in addition to the log. Also,
CGIHandlerdoesn't fully accommodate long running processes and may leak data between requests through environment variables. run_wsgi_app() properly resets the environment between requests, and is the recommended way to start a WSGI app on App Engine.
- A WSGI application object, such as webapp.WSGIApplication.
from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class MainPage(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!') application = webapp.WSGIApplication([('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main()