Django got an unexpected keyword argument ‘id’

Each Answer to this Q is separated by one/two green lines.

I’m trying to create a phonebook in Django.

    urlpatterns = [
    url(r'^$', views.people_list, name="people_list"),
    url(r'^(?P<id>\d)/$', views.person_detail, name="person_detail"),

def people_list(request):
    people = Person.objects.all()
    return render(request, 'phonebook/person/list.html', {'people': people})

def person_detail(request, person):
    person = get_object_or_404(Person, id=person)
    return render(request, 'phonebook/person/detail.html', {'person': person})


def get_absolute_url(self):
    return reverse('phonebook:person_detail', args=[])

and list.html:

{% block content %}
{% for person in people %}
    <a href="{{ person.get_absolute_url }}">
        {{ }} {{ person.last_name }}
<p class="where">
{{ person.department }}, {{ person.facility }}
{{ person.phone1 }}<br>
{% endfor %}
{% endblock %}

The index looks ok but when I try click on links to get person_detail site I get this message:

TypeError at /phonebook/4/
person_detail() got an unexpected keyword argument ‘id’
Request Method: GET Request
URL: Django Version: 1.9.6
Exception Type: TypeError Exception Value: person_detail() got an
unexpected keyword argument ‘id’

I have and ‘id’ argument in and in function to get_absolute_url. I don’t understand what’s wrong.

Your parameter ?P<id> in the URL mapping has to match the arguments in the view def person_detail(request, person):

They should both be id or both person.

You should fix the view and use the id argument name instead of person:

def person_detail(request, id):

My mistake was I only added the first parameter instead of both,i.e I mentioned def person_detail(request) instead of def person_detail(request,id)

The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .