Tuesday, April 22, 2014

Tutorial Part4: object_list() got an unexpected keyword argument 'object_id'

At the end of tutorial part 4, I got following error message and could not get displayed the result page.
Request Method: GET
Request URL: http://127.0.0.1:8000/polls/1/result/
Django Version: 1.3.1
Exception Type: TypeError
Exception Value:
object_list() got an unexpected keyword argument 'object_id'
Exception Location: /usr/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response, line 111

Here is the copy of each related codes.

results.html:
<h1>{{ object.question }}</h1>
<ul>
{% for choice in object.choice_set.all %}
    <li>{{choice.choice }}  -- {{ choice.votes }} Hyou</li>
{% endfor %}
</ul>

urls.py:
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),
    url(r'^(?P<object_id>\d+)/result/$', 'django.views.generic.list_detail.object_list', dict(info_dict, template_name='pol
    (r'^(?P<poll_id>\d+)/vote/$', 'mysite.polls.views.vote'),
...

views.py:
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.DoseNotExist):
        return redner_to_response('polls/poll_detail.html',
                                  {
                                    'object': p,
                                    'error_message': "You didn't choice.",
                                  })
    else:
        selected_choice.votes += 1
        selected_choice.save()     
        return HttpResponseRedirect(reverse('poll_results', args=(p.id,)))


I suspected the mis-update of poll to object or latest_poll_list to object_list but it seems fine to me...
It will be very nice if I can complete this and move on to the next level.

Thanks in advance.

Kenji

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/0bde8e3f-7fb5-4c4a-9f35-fcfc496b57a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment