Opened 10 years ago

Closed 10 years ago

#22700 closed Bug (invalid)

Wrong signature of def vote() in generic views

Reported by: cmeter@… Owned by: nobody
Component: Documentation Version: 1.6
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In the tutorial on Django v1.6 Part 4 you wrote in "Amend Views" (https://docs.djangoproject.com/en/1.6/intro/tutorial04/#amend-views) in the last block of code this line:

def vote(request, poll_id):
  ....

But after changing to generic views, the method should look like this:

def vote(request, pk):
  p = get_object_or_404(Poll)
  ...

Otherwise the poll application won't work and throws this error:

TypeError at /polls/1/vote/
vote() got an unexpected keyword argument 'pk'
Request Method: POST
Request URL: http://127.0.0.1:8000/polls/1/vote/
Django Version: 1.6.5
Exception Type: TypeError
Exception Value:
vote() got an unexpected keyword argument 'pk'
Python Version: 3.4.1

Change History (1)

comment:1 by Tim Graham, 10 years ago

Resolution: invalid
Status: newclosed

I think you made a mistake. The URLconf in the block above still uses poll_id rather than pk: url(r'^(?P<poll_id>\d+)/vote/$', views.vote, name='vote'),

Note: See TracTickets for help on using tickets.
Back to Top