How to store user specific data in Django

Viewed 44

In Django, How can we store user specific data?

I'm trying to creating a django web app, where user needs to remember the order of random sequence fetched from database.

I have two functions in my views, home and result

I tried to store random sequence generated by home function into a global variable, and use that to validate in results function.

But , I think this can serve only one user at time

What if second user requested for home page and that cause change in global variable, resulting unable to validate first user.

1 Answers

You can tackle the problem with Django Session.

In home view you can set variables by :

request.session['varibale_name'] = varibale_value

You can access these variables in result view by :

request.session['varibale_name']

After job done you can also delete the session variable by :

del request.session['varibale_name']
Related