Answer the question
In order to leave comments, you need to log in
How do I get data out of a Django model?
I have three pages where you can vote for 1 object.
On them you click on the "Choose" button and the result is displayed on the main page.
black.html
<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">{{ count_black }}</h1> <!-- временный просмотр голосов-->
</form>
#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)
def black(request):
#пример переменной: name = Choose.objects.all()
if request.method == 'POST':
select_action = request.POST['choose']
if select_action == 'black':
Choose.count_black += 1
# return redirect("home")
Choose.save()
return render(request, 'registration/black.html')
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