I'm new to Django and I've been able to get to the end of the Django
tutorial using localhost as my server. for some reason I can't get the
form poll to recognize my choices. Regardless whether I click on the
radio buttons and click vote or if I just click vote without
selecting, I always get the screen saying "You didn't select a
choice".
Here is code from my urls.py ->
from django.conf.urls.defaults import *
from djangoblogproject.polls.models import Poll
info_dict = {
'QuerySet': Poll.objects.all(),
}
urlpatterns = patterns('',
(r'^$',
'django.views.generic.list_detail.object_list',info_dict),
(r'^(?P<object_id>\d+)/$',
'django.views.generic.list_detail.object_detail',info_dict),
(r'^(?P<object_id>\d+)/results/$',
'django.views.generic.list_detail.object_detail', dict(info_dict,
template_name = 'polls/results.html')),
(r'^(?P<poll_id>\d+)/vote/$',
'djangoblogproject.polls.views.vote'),
)
and here is the code from my views.py file ->
from djangoblogproject.polls.models import choice, Poll
from django.shortcuts import render_to_response, get_object_or_404
from django.http import HttpResponseRedirect
def vote(request, poll_id):
p = get_object_or_404(Poll, pk = poll_id)
try:
selected_choice = p.choice_set.get(pk =
request.POST['choice'])
except (KeyError, choice.DoesNotExist):
return render_to_response('polls/poll_detail.html', {
'object': p,
'error_message': "You didn't select a choice.",
})
else:
selected_choice.votes +=1
selected_choice.save()
return HttpResponseRedirect('/polls/%s/results/' % p.id)
Anybody know what is causing the problem?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---