in a form, I submit data to a python webapp handler (all Google App Engine based) using a HTTP POST request. In this script, I first check if the user is logged in and if not, I use users.create_login_url(...) to redirect the user first to the login page.
How can I ensure that after login the user is not just forwarded to my python script again, but that also the POST variables are preserved? The only way I found was turning all POST variables into URL parameters and adding it to the URL.
Is that possible at all?
Normally, I'd store it in session variables. I've used gae-sessions before and found it easy. It persists to the datastore and memcaches behind the scenes for speed. Looks like this:
from gaesessions import get_current_session
session = get_current_session()
if session.is_active():
c = session.get('counter', 0)
session['counter'] = c + 1
session['blah'] = 325
del session.blah # remove 'blah' from the session
Or you could be all HTML5y and use localStorage.
The general problem with capturing a POST and turning it into a GET is first that the query string on a GET has a browser-dependent limited size, and second that a POST may be form/multi-part (what to do with the uploaded file becomes an issue).
An approach that might work for you is to accept the POST and save the data, then redirect to a page that requires login, passing the Key(s) (or enough information to reconstruct them) in the query string. The handler for that URL then assumes successful login, and fixes up the saved data (say, to associate it with the logged-in user) as appropriate.
People who decide not to login will leave orphaned records, which you can clean up via a cron job.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With