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

68 views
Skip to first unread message

Okabe Kenji

unread,
Apr 22, 2014, 3:10:59 AM4/22/14
to django...@googlegroups.com
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

Tom Evans

unread,
Apr 22, 2014, 9:57:09 AM4/22/14
to django...@googlegroups.com
On Tue, Apr 22, 2014 at 8:10 AM, Okabe Kenji <hipe...@gmail.com> wrote:
>
> 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

Django 1.3 is ancient, unsupported and full of security holes.
Unsupported means that you shouldn't expect a lot of help with it,
particularly as this is a tutorial you are running through, not a
pre-existing project with lots of 1.3-era code.

> 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'),

So, looking at the tutorial for Django 1.3, this code does not appear
at all. The tutorial for Django 1.3 tells you about DetailView and
ListView in the "generics" section of the tutorial. This code in fact
comes from the tutorial for Django 1.2.

Mixing the tutorial for Django 1.2 with the code from Django 1.3 is
not going to work well.

My advice: start again from scratch. Install the latest release of
django, that is Django 1.6.3, and follow the Django 1.6 tutorial.


Cheers

Tom
Reply all
Reply to author
Forward
0 new messages