At first glance everything seems to work until I vote. Then instead of going to http://localhost:8000/polls/1/results/ it stays on http://localhost:8000/polls/1/vote/ and the only thing displayed in the browser (both firefox and chrome do this) is /polls/1/results/. My view and url code for results and vote will be posted below. Does anyone know what could cause this ?
views
#question id of results
def results(request, question_id):
question = get_object_or_404(Question, pk=question_id)
return render(request, "polls/results.html", {"question": question})
#what question are you voting on?
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 = F("votes") + 1
selected_choice.save()
return HttpResponse(reverse("polls:results", args=(question.id,)))
urls
#ex: /polls/5/results/
path("<int:question_id>/results/", views.results, name="results"),
#ex: /poll/5/vote/
path("<int:question_id>/vote/", views.vote, name="vote"),
any help would be greatly appreciated