I am trying to count in my Django website. I use a global variable testc to count (I know this caused the problem, but I don't know how to do the counting without a global variable). So if two browser open the website (threadtest.html) in the same time, they will both increase the same testc (of course). Is there a way to do count individually in each browser session? Do I need to use multi-thread? Thanks.
Here is my 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 is the 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 is </h1>
<h1> {{count}} </h1>
<form action="/threadtest/" method="post">{% csrf_token %}
<input type= "submit" name = "button" value = "addit" />
</form>
{% endblock %}
</body>
</html>