January 2015
Intermediate to advanced
198 pages
4h 27m
English
The first requirement for our Notes application is showing the home page only to users who are logged in and redirect others to the login form; the users service provided by App Engine is exactly what we need and adding it to our MainHandler class is quite simple:
import webapp2
from google.appengine.api import users
class MainHandler(webapp2.RequestHandler):
def get(self):
user = users.get_current_user()
if user is not None:
self.response.write('Hello Notes!')
else:
login_url = users.create_login_url(self.request.uri)
self.redirect(login_url)
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)The user package we import on the second line of the previous code provides access to users' service functionalities. ...
Read now
Unlock full access