Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:56:27+00:00 2026-06-16T19:56:27+00:00

I tried to implement GAE’s webapp2 session, but there seems very little documentation about

  • 0

I tried to implement GAE’s webapp2 session, but there seems very little documentation about it. According to http://webapp-improved.appspot.com/api/webapp2_extras/sessions.html, my steps are as follows:

1.Configure and add config to the main application:

config = {}
config['webapp2_extras.sessions'] = {
    'secret_key': 'my_secret_key',
}
app = webapp2.WSGIApplication([...], config=config)

2.Create session in the login handler

# Delete existent session
  --> not mention in the tutorial
# member is found    
self.session_store = sessions.get_store(request=handler.request)
self.session['account'] = member.account

3.Check if a session exists at various locations in my program

if self.session['account']:
    # Session exists

4.Delete session when user logs out

--> not mentioned in the tutorial

My questions:

  1. I got error message ” … object has no attribute ‘session'” during the session creation process (Step 2)

  2. How do I delete a session in steps 2 and 4?

  3. Is the overall session management process correct?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:56:28+00:00Added an answer on June 16, 2026 at 7:56 pm

    This may not be a direct answer to the question, but it is a solution I found using gaesessions instead of GAE’s webapp2 session and I would like to share with everybody. Here we go:

    1. Download gaesessions from https://github.com/dound/gae-sessions by clicking “Download ZIP” button. The downloaded file is “gae-sessions-master.zip”.

    2. Unzip the file (a directory “gae-sessions-master” will be created), and copy the directory “gaessions” to the root directory of your application (i.e., where “app.yaml” is)

    3. Create a file called “appengine_config.py” in the root directory, with the following content (copied form https://github.com/dound/gae-sessions/tree/master/demo):

      from gaesessions import SessionMiddleware
      
      # Original comments deleted ... 
      # Create a random string for COOKIE_KDY and the string has to
      # be permanent. "os.urandom(64)" function may be used but do
      # not use it *dynamically*.
      # For me, I just randomly generate a string of length 64
      # and paste it here, such as the following:
      
      COOKIE_KEY = 'ppb52adekdhD25dqpbKu39dDKsd.....'
      
      def webapp_add_wsgi_middleware(app):
          from google.appengine.ext.appstats import recording
          app = SessionMiddleware(app, cookie_key=COOKIE_KEY)
          app = recording.appstats_wsgi_middleware(app)
          return app
      
    4. Create a session when a user logs in (variable account is the user’s account):

      from gaesessions import get_current_session
      session = get_current_session()
      if session.is_active():
          session.terminate()
      # start a session for the user (old one was terminated)
      session['account'] = account
      
    5. Check if the user’s session exists, if yes, return user’s account:

      from gaesessions import get_current_session
      def checkSession():
          session = get_current_session()
          if session.is_active():
              return session['account']
          return False
      
    6. Delete the session when the user logs out:

      def logout():
          session = get_current_session()
          if session.is_active():
              session.terminate()
      
    7. Finally, you may create a cron job to clean expired sessions periodically:

    cron.yaml:

    - description: daily session cleanup
      url: /clean_up_sessions
      schedule: every day 3:00
      timezone: ... (Your time zone)
    

    Function:

    from gaesessions import delete_expired_sessions
    class clean_up_sessions(webapp2.RequestHandler):
        def get(self):
            while not delete_expired_sessions():
                pass
    

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried to implement this captcha http://www.dracon.biz/captcha.php to a script But It seems really
I tried to implement IEnumerator< Status > but got errors about two different Properties
I've tried to implement the 'Layout with Dijit' tutorial http://dojotoolkit.org/documentation/tutorials/1.7/dijit_layout/ as a JSP. My
I tried to implement the subtract method but got there are some bugs. 55-44
I've tried to implement this CSS3 slideshow on my site ( http://www.designmadeingermany.de/slideshow/ ) But
I tried to implement __concat__ , but it didn't work >>> class lHolder(): ...
I tried to implement FizzBuzz in DCPU-16. I use this web emulator: http://mappum.github.com/DCPU-16/ (repository:
I have tried to implement css sticky footer on my page but it doesn't
Are there some good resources tutorials or anyone has tried to implement a Capcha
Does anyone have tried to implement an app in GAE having both java and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.