How to store user specific data in Django

Question:

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.

Asked By: Hari

||

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']
Answered By: Manoj Kamble
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.