I have a problem with Django session and i have no idea how to solve it. Basically i store some data in the session
dictionary in one view function, and calculate some thing in a second function using the values from the first view. Now if someone opens up two tabs, fills in the data in one and submits it, fills the second tab and submits it, the session dictionary will be the same for both tabs. I hope i phrase myself right.
Simple explanation:
def a(request):
request.session["q"] = request.POST.get('q')
def b(request):
while True:
print(request.session["q"])
So lest assume function a
is rendering an index page, and getting a value from there. On a button push in this index
page function b
is called. Now if i open two tabs, input 1
in to the index page and submit i ll see a lot of 1 in the terminal. Now i open up another tab, input 2
, submit, the printing will change.
What i would like to do is to keep separate sessions (separate information to come in and go out) from my server to the user on different tabs of a browser.
I am sorry if i phrase myself wrong, this is the first time i am trying to work with web servers.
EDIT:
As i mentioned in the comments the answer is currently not working, and i think it is just a syntax error, however i dont know where i gone wrong.
My template:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
{% load staticfiles %}
<HTML>
<HEAD>
<LINK rel="stylesheet" type="text/css" href="{% static 'style7.css' %}"/>
<link rel="shortcut icon" type="image/png" href="{% static 'favicon.ico' %}"/>
<script src="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.13.min.js"></script>
<link rel="stylesheet" href="http://cdn.bokeh.org/bokeh/release/bokeh-0.12.13.min.css">
<script type="application/javascript">function makeid() {
var text = "";
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
for (var i = 0; i < 5; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length));
return text;
}
document.getElementById("session").value = makeid();</script>
</HEAD>
<BODY>
....
....
<form action="{% url 'raw' %}" method="post" style="float: left;">{% csrf_token %}<input type="hidden" name="session" id="session"><input type="submit" value="Download text"/></form>
....
My view function:
def plot(request):
print(request.POST.get("session"))
....
However in the terminal see nothing printed, thus i think the variable is an empty string.