title: Login and logout with web.py
body: <p>I have a little problem with web.py. Exacly I have problem with sessions.</p>
  
  <p>Link to my app:
  <a href="http://len.iem.pw.edu.pl/~witkowr1/apps/demo/" rel="nofollow">http://len.iem.pw.edu.pl/~witkowr1/apps/demo/</a></p>
  
  <p>Login/password: wtq/wtq</p>
  
  <p>Code:</p>
  
  <pre><code>    # -*- coding: utf-8 -*- 
  import web 
  import json
  from web.contrib.template import render_jinja
  import datetime
  
  prefix = '/~witkowr1/apps/demo'
  
  urls = (
      prefix + '/login','Login',
      prefix + '/logout','Logout',
      prefix + '/', 'Index',
  )
  
  app = web.application(urls, globals())
  wsgi = app.wsgifunc()
  session = web.session.Session(app, web.session.DiskStore('sessions'),initializer={'time':datetime.datetime.now()})
  render = render_jinja('static', encoding = 'utf-8')
  render._lookup.globals.update(assets=prefix+'/static')
  
  class Login:
      def GET(self):
      web.seeother(prefix+'/')
  
      def POST(self):
          login = web.input().login
      password = web.input().passwd
      if login == 'wtq' and password == 'wtq':
              session.logged_in = True
              session.time = datetime.datetime.now()
              last_login = web.cookies().get('time')
              if last_login == None:
                  last_login_data = u'ZalogowaĹ‚eĹ› siÄ™ pierwszy raz.'
              else:
                  last_login_data = last_login
          return render.logged(name=login, date_last_login=last_login_data)
          else:
              session.logged_in = False
          error=u'Niepoprawne dane. SprĂłbuj jeszcze raz.'
              return render.login(error_msg=error)
  
  class Logout:
      def GET(self):
          web.seeother(prefix+'/')
  
      def POST(self):
          session.logged_in = False
          web.setcookie('time',session.time)
          message = u'ZostaĹ‚eĹ› poprawnie wylogowany.'
          session.kill()
          return render.login(error_msg=message)
  
  class Index:
      def GET(self):
          return render.login()
  
  if __name__ == "__main__":
      app.run()
  </code></pre>
  
  <p>I would like to verify session and if I login early, I see site with latest login date.
  Now, when I refresh the site, I must login again.
  I think, that I check session, when I rendering HTML site, but I don't know, what I do it.</p>
  
  <p>Please help!</p>