Reputation: 249
I'm trying to create user sessions as explained here http://www.essentialtech.co.nz/content/using_session_google_app_engine_and_python_27 . Below is the Login page handler class. Everything is fine, but I'm not able to understand what the 'self.session.get('referrer')' would do. I googled for it and found that 'HTTP_REFERER' refers to the site url where you are coming from. But why do we need it in the Login handler here? I feel glad if some one can explain it to me.
class LogIn(BaseHandler):
def get(self):
if self.session.get('user'):
del self.session['user']
if not self.session.get('referrer'):
self.session['referrer'] = \
self.request.environ['HTTP_REFERER'] \
if 'HTTP_REFERER' in self.request.environ \
else '/'
template_values = {
}
template = jinja_environment.get_template('login.html')
self.response.out.write(template.render(template_values))
def post(self):
user = self.request.get('user')
self.session['user'] = user
logging.info("%s just logged in" % user)
self.redirect('/')
Upvotes: 3
Views: 86
Reputation: 5424
I presume it's used to know where to redirect the user after login. But the POST redirects to '/' so doesn't look like it's plugged in, at least not in this snippet. This doesn't make sense though, if you come in from a totally different website. So maybe it's just used for logging / tracking purposes. Again, not detailed in this snippet.
Upvotes: 2