Answer the question
In order to leave comments, you need to log in
Why does the click disappear when going to the page?
Using Python, django
I have a button on my page that counts the number of clicks on it. When I refresh the page, this number is saved, but if I go to another page, the value is reset to zero.
views.py:
def black(request):
value = Choose()
if request.method == 'POST':
select_action = request.POST['choose']
if select_action == 'black':
value.count_black += 1
value.save()
# return redirect("home")
context = {"value": value}
return render(request, 'registration/black.html', context)
models.py:
from django.db import models
class Choose(models.Model):
count_black = models.PositiveIntegerField(default=0)
count_white = models.PositiveIntegerField(default=0)
count_purple = models.PositiveIntegerField(default=0)
<form method="post">
{% csrf_token %}
<button class="button_b" name="choose" value="black">
<h1 style="color: white">
<strong>Choose</strong>
</h1>
</button>
<h1 style="color: red">{{ value.count_black }}</h1> {# строка, выводящая значение #}
</form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question