multithreading - How to use different global variable for different browser sessions in Django website -


i trying count in django website. use global variable testc count (i know caused problem, don't know how counting without global variable). if 2 browser open website (threadtest.html) in same time, both increase same testc (of course). there way count individually in each browser session? need use multi-thread? thanks.

here view:

testc=0 def threadtest(request):     global testc     if request.method == 'post':         testc=testc+1         print testc     return render(request,'threadtest.html',{'count':testc,}) 

here template: base.html

{% load staticfiles %} {% load static %} {% load extra_tags %} <html> <head> <title>{% block title %}{% endblock %}</title>   {%block myscripts %}{% endblock %}  </head> <body> <div id="content">     {% block content %}{% endblock %} </div>  </body> </html> 

threadtest.html

{% extends 'base.html' %} <html> <head><title></title></head>  <body>  {% block content %} <h1> current count </h1> <h1> {{count}} </h1> <form action="/threadtest/" method="post">{% csrf_token %} <input type= "submit" name = "button" value = "addit" /> </form> {% endblock %} </body> </html> 

you can info from:

request.meta['http_user_agent'] 

some output example:

   mozilla/5.0 (x11; linux i686) applewebkit/537.36 (khtml, gecko) chrome/28.0.1500.70 safari/537.36 

maybe can find helpful snippet


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -