Reputation: 57
I'm trying to create a simple form, but somehow everytime I push the enter button, this error shows up? so what did I do wrong?
This is my views :
@login_required
def voted(response):
user = Userdata.objects.get(id=response.user.id) # get the username
if user.is_voted == True:
return render(response, 'Main/voting.html', {'calon' : Voting.objects.order_by('id'), 'hasil' : 'You Have Voted'})
if response.method == 'POST':
id = int(response.POST.get['idcalon'])
calon2 = Voting.objects.get(id = id) # get user selection in html
user.is_voted = True
calon2.voters += 1
user.save()
calon2.save()
return render(response, 'Main/voting.html', {'calon' : Voting.objects.order_by('id')}) # balik ke sendiri
This is the Html :
<form method="POST">
{% if calon %}
{% for para in calon %}
<div class="custom-control custom-checkbox small" style="line-height: 1.5rem;">
<input type="radio" id="huey" name="idcalon" value="{{ forloop.counter }}" checked>
<label for="huey">{{ para.name }}</label> </div>
{% endfor %}
{% else %}
{% endif %}
<div class="form-group">
<div class="col-sm-10">{% csrf_token %}
<button type="submit" class="btn btn-primary">Vote Now</button></div>
</div>
</form>
My guest is at the value in the HTML, but I personally don't know how to fix it. Thank you
Upvotes: 1
Views: 362
Reputation: 88589
The .get()
is a method and you should've call it with using paranthesis as,
response.POST.get('idcalon')
You can also retrieve the desired value from request.POST
by
response.POST['idcalon']
Upvotes: 2