# please help. got an unexpected keyword argument. Template.

**URL:** <https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041>\
**Category:** Mystery Errors\
**Created:** [July 3, 2023, 4:24am UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041 "2023-07-03T04:24:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 3, 2023, 4:24am UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/1 "2023-07-03T04:24:23Z")

</div>

hello! Please help me.

url.py

```auto
path("table_details/<int:table>", views.table_details, name="table_details")

```

views.py

```auto
def table_details(request):
    
    table = request.GET.get("table")
    
    return render(request, 'main/table_details.html', {'table': table})

```

1.html

```auto
<a href="{% url 'table_details' 745 %}" class="nav-link text-white">

```

table\_details.html

```auto
{% extends 'main/1.html' %}

{%block content%}

{{table}}

{%endblock content%}

```

error

```auto
TypeError at /table_details/745
table_details() got an unexpected keyword argument 'table'
Request Method:	GET
Request URL:	http://127.0.0.1:8000/table_details/745
Django Version:	4.2.1
Exception Type:	TypeError
Exception Value:	
table_details() got an unexpected keyword argument 'table'

```

---

<div class="post-metadata">

**Author:** ![plopidou](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/plopidou/32/5148_2.png) [@plopidou](https://forum.djangoproject.com/u/plopidou)\
**Post date:** [July 3, 2023, 8:47am UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/2 "2023-07-03T08:47:23Z")

</div>

this is wrong almost everywhere 🙂

- a GET parameter is not the same a as url/path keyword argument.
- the `url` template call is wrong (missing a kwarg key/name)
- a GET parameter cannot contain a `Table` object. You have to fetch the object itself in the view, using the Django ORM.
- your call `request.GET.get("table")` implies a url similar to `/table_details?table=745`… which is not matched by anything
- do not play with template inheritance until you have 100% mastered the basics above. The way you use it hardly makes any sense.

try this (or similar), but only after understanding your errors:

urls:

```auto
path("table_details/<int:table_pk>", views.table_details, name="table_details")

```

views:

```auto
def table_details(request):
    
    try:
        table = Table.objects.get(pk=self.kwargs['table_pk'])
    except Table.DoesNotExist:
        return Http404
    
    return render(request, 'main/table_details.html', {'table': table})

```

table\_details.html

```auto
<a href="{% url 'table_details' table_pk=table.pk %}">{{ table.title }}</a> # or whatever other field..

```

---

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 3, 2023, 4:54pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/3 "2023-07-03T16:54:56Z")

</div>

> [@plopidou](#):
>
> his is wrong almost everywhere 🙂
> 
> - a GET parameter is not the same a as url/path keyword argument.
> - the `url` template call is wrong (missing a kwarg key/name)
> - a GET parameter cannot contain a `Table` object. You have to fetch the object itself in the view, using the Django ORM.
> - your call `request.GET.get("table")` implies a url similar to `/table_details?table=745`… which is not matched by anything
> - do not play with template inheritance until you have 100% mastered the basics above. The way you use it hardly makes any sense.
> 
> try this (or similar), but only after understanding your errors:

BIG THANX 🤝 🙂

---

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 3, 2023, 5:02pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/4 "2023-07-03T17:02:55Z")

</div>

But I found another solution )

urls

```auto
re_path(r'table_details/', views.table_details, name="table_details"),

```

views

```auto
def table_details(request):
table = request.GET.get("table")
    table = int(table)
return render(request, 'main/table_details.html', {'table': table)

```

html

`<a href="{% url 'table_details' %}?table=745">`

it also works!)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 3, 2023, 5:08pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/5 "2023-07-03T17:08:07Z")

</div>

Yes, it works, but it’s not the “Django-style” way of handling this.

---

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 3, 2023, 5:11pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/6 "2023-07-03T17:11:15Z")

</div>

Yes, I understand that Django has its own philosophy, I will connect and study. Thank you.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 3, 2023, 5:19pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/7 "2023-07-03T17:19:25Z")

</div>

It’s not just a philosophy, it’s also a set of built-in features and safeguards that prevent you from needing to do some of the work.

For example, in the method you have implemented, there is no validation that the value submitted for `table` is actually a proper integer suitable for use as a key.

However, if you have your url defined as described above:  
`path("table_details/<int:table_pk>", views.table_details, name="table_details")`  
then Django will have verified that the entry supplied in the url in that position is an integer. Your view won’t even be called unless it passes the appropriate tests.

---

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 3, 2023, 5:28pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/8 "2023-07-03T17:28:01Z")

</div>

yes, I agree with you, everything is true, I understand, but I’m a beginner, and I’m still figuring it out, and sometimes a ready-made solution in Django can’t always be understood immediately by a beginner. Therefore, something has to be done in its own way. But in my case, this concept suits me, because there will be no other values except the type of numbers in the link.  
**Thanks again!**

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [July 3, 2023, 5:36pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/9 "2023-07-03T17:36:10Z")

</div>

No one denies that there’s a fairly substantial learning curve with Django. That’s one of the reasons why there’s a community of people here to help you along.

You are only impeding your own education and professional development as a Django programmer by ignoring what Django provides for you in favor of an alternative and inferior approach to the well-defined, documented, and standard method of passing parameters into views.

> [@vickodinn](#):
>
> there will be no other values except the type of numbers in the link.

That statement is not accurate. You have no mechanism to prevent a user from changing the value supplied in a url.

Making the assumption that you have any control at all over any data being submitted is the primary cause of most security vulnerabilities. The number one security rule in the development of any web application is that you **must not** trust any data coming from the browser.

---

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 3, 2023, 5:39pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/10 "2023-07-03T17:39:41Z")

</div>

> [@KenWhitesell](#):
>
> Making the assumption that you have any control at all over any data being submitted is the primary cause of most security vulnerabilities. The number one security rule in the development of any web application is that you **must not** trust any data coming from the browser.

Thank you, I will keep in mind!

---

<div class="post-metadata">

**Author:** ![plopidou](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/plopidou/32/5148_2.png) [@plopidou](https://forum.djangoproject.com/u/plopidou)\
**Post date:** [July 3, 2023, 8:06pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/11 "2023-07-03T20:06:11Z")

</div>

try this:

`<a href="{% url 'table_details' %}?table=hellothere">`

how does your code behave with this?

---

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 7, 2023, 9:44pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/12 "2023-07-07T21:44:49Z")

</div>

> [@plopidou](#):
>
> how does your code behave with this?

it works without errors during testing.  
Do you think this is wrong?

---

<div class="post-metadata">

**Author:** ![plopidou](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/plopidou/32/5148_2.png) [@plopidou](https://forum.djangoproject.com/u/plopidou)\
**Post date:** [July 10, 2023, 7:51am UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/13 "2023-07-10T07:51:02Z")

</div>

did you click the link?

---

<div class="post-metadata">

**Author:** ![vickodinn](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/vickodinn/32/14565_2.png) [@vickodinn](https://forum.djangoproject.com/u/vickodinn)\
**Post date:** [July 10, 2023, 9:43pm UTC](https://forum.djangoproject.com/t/please-help-got-an-unexpected-keyword-argument-template/22041/14 "2023-07-10T21:43:42Z")

</div>

yes, I followed the link and everything works correctly
