3 August 2010

This tutorial shows how to make Log In, Log Out and Register links for Google App Engine in Python.

Example Code:

The Log In and Register part is made by Google and is in the framework so there is nothing else to than just to generate the links.
Source code viewer
  1. from google.appengine.api import users
  2. from google.appengine.ext import webapp
  3. from google.appengine.ext.webapp.util import run_wsgi_app
  4.  
  5. class MainPage(webapp.RequestHandler):
  6. def get(self):
  7. user = users.get_current_user()
  8. if not user:
  9. login_links = ('<a href="%s">Log In or Register</a>'
  10. % (users.create_login_url(self.request.path)))
  11. else:
  12. login_links = ('<p>Welcome, %s! You can <a href="%s">Log Out</a>.</p>'
  13. % (user.nickname(), users.create_logout_url(self.request.path)))
  14. self.response.headers['Content-Type'] = 'text/html'
  15. self.response.out.write('''
  16. <html>
  17. <head>
  18. <title>Log In, Log Out and Register links</title>
  19. </head>
  20. <body>
  21. %s
  22. </body>
  23. </html>
  24. ''' % (login_links))
  25. application = webapp.WSGIApplication([
  26. ('/', MainPage)],
  27. debug=True)
  28. def main():
  29. run_wsgi_app(application)
  30. if __name__ == '__main__':
  31. main()
Programming Language: Python