Hi everyone I am getting started with Django.
My doubt is about the tutorial called ‘Writing our first Django app’ For everyone who doesn’t know about it, it’s a tutorial where you start developing a polls app. I am in the part where i have to do the forms. I am doing part 4: https://docs.djangoproject.com/en/1.11/intro/tutorial04/ and it’s happening to me the following situation: polls/templates/polls/detail.html <h1>{{ question.question_text }}</h1> {% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %} <form action="{% url 'polls:vote' question.id %}" method="post"> {% csrf_token %} {% for choice in question.choice_set.all %} <input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" /> <label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br /> {% endfor %} <input type="submit" value="Vote" /> </form> polls/views.py from django.shortcuts import get_object_or_404, render from django.http import HttpResponseRedirect, HttpResponse from django.urls import reverse from .models import Choice, Question # ... def vote(request, question_id): question = get_object_or_404(Question, pk=question_id) try: selected_choice = question.choice_set.get(pk=request.POST['choice']) except (KeyError, Choice.DoesNotExist): # Redisplay the question voting form. return render(request, 'polls/detail.html', { 'question': question, 'error_message': "You didn't select a choice.", }) else: selected_choice.votes += 1 selected_choice.save() # Always return an HttpResponseRedirect after successfully dealing # with POST data. This prevents data from being posted twice if a # user hits the Back button. return HttpResponseRedirect(reverse('polls:results', args=(question.id,))) def results(request, question_id): question = get_object_or_404(Question, pk=question_id) return render(request, 'polls/results.html', {'question': question}) polls/templates/polls/results.html <h1>{{ question.question_text }}</h1> <ul> {% for choice in question.choice_set.all %} <li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li> {% endfor %} </ul> <a href="{% url 'polls:detail' question.id %}">Vote again?</a> I am doing the polls app, and when i hit the button ‘Vote’, the page always shows me the error message: “You didn’t select any choice.” Moreover, it doesn’t show any radio button to select a certain choice and once i have hit the button, it never redirects me to the results page. Also, i can’t see the number of votes in the results page. I have reviewed several times the code, and it looks like the same as the tutorial one. (Even, i have replaced it but it doesn’t work) Any idea about why the input element doesn’t show in the choice page and doesn’t allow me to vote? Thanks for help beforehand Rafa Libre de virus. www.avast.com --- El software de antivirus Avast ha analizado este correo electrónico en busca de virus. https://www.avast.com/antivirus -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/59676a29.4c3e1c0a.f78f.862b%40mx.google.com. For more options, visit https://groups.google.com/d/optout.

