Question

I have a webapp that allows authenticated as well as anonymous users to start entering some form data. If a user is happy with his/her input, he/she can save that form to the server. This is a very similar problem to a shopping cart application that does not require login until checkout time.

For the authenticated user, implementing a save button is trivial. However for the anonymous user, the form data need to be stored somewhere while authentication is taking place, then correctly retrieved after logged in. Can someone please suggest some general strategies to go about this?

I found this link that is promising but I want to be thorough about this topic.

Was it helpful?

Solution

I think the correct way of doing this is to use django sessions. Basically each user (anonymousUser included) has a session during its stay on the website (or even more).

If you have a form that you want to store for a specific session, you can do it by using

 request.session['myform'] = form

you get it by

request.session['myform']

and you can delete it using

 del request.session['myform']

Basically Django pickles a dictionary of the session and saves it in a place (typically the database, but can be on other place as explained in django sessions).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top