views:

193

answers:

2

I'm writing a simple app with AppEngine, using Python. After a successful insert by a user and redirect, I'd like to display a flash confirmation message on the next page.

What's the best way to keep state between one request and the next? Or is this not possible because AppEngine is distributed? I guess, the underlying question is whether AppEngine provides a persistent session object.

Thanks

Hannes

+3  A: 

No session support is included in App Engine itself, but you can add your own session support.

GAE Utilities is one library made specifically for this; a more heavyweight alternative is to use django sessions through App Engine Patch.

Wooble
Another good option is Beaker, which supports datastore, memcache, and encrypted cookie sessions.
Nick Johnson
Great, thanks! gaeutilities does exactly what I'm looking for!
Hannes
+2  A: 

The ways to reliable keep state between requests are memcache, the datastore or through the user (cookies or post/get).

You can use the runtime cache too, but this is very unreliable as you don't know if a request will end up in the same runtime or the runtime can drop it's entire cache if it feels like it.

I really wouldn't use the runtime cache except for very specific situations, for example I use it to cache the serialization of objects to json as that is pretty slow and if the caching is gone I can regenerate the result easily.

Koen Bok
Ah, maybe I answered too fast. But surely this applies to implementing sessions too.
Koen Bok
Koen's right, the easiest way would be use a URL param or cookie. Just make sure you cleanse it properly for XSS and/or use a mapping of codes to messages or something. Beyond that, look to a custom session solution using memcache or datastore.
RyanW