I'm struggling with following problem:
fachbereich_detailview() got an unexpected keyword argument 'pzn'
The error tells me that there is something wrong with my urls. If I change the last part of the url to int:test, it tells me that the unexpected keyword argument is test.
The query 'product = Products.objects.get(pzn="existingpzn")' is working fine (Tested with shell).
view.py:
[...]
def fachbereich_detailview(request, pzn):
context = {}
try:
product = Products.objects.get(pzn=pzn)
except:
return redirect('fachbereich')
context['product'] = product
return render(request, 'app/LoginArea/fachbereich_detailview.html', context)
[...]
urls.py:
[...]
path('Produkt/<int:pzn>/', views.fachbereich_detailview, name='fachbereich_detailview'),
[...]
html:
<a href="{% url 'fachbereich_detailview' product.pzn %}" >Mehr erfahren</a>
I just can't figure out what the problem is.
I hope that someone is able to help me!
Thank you in advance Nader
CodePudding user response:
It is because you are setting integer
in your url, but you are passing string
to your view. Change your url to that:
path('Produkt/<str:pzn>/', ...),