Reputation: 1007
Django tries the wrong url pattern but I can not find my mistake.
urls.py
url(r'^message/(?P<advertisementid>(\d+))/$', chat_view, name="chat_view_with_toid"),
url(r'^profile/(?P<userid>(\d+))/$', profile_view, name="profile"),
url(r'^details/(?P<advertisementid>(\d+))/$', details_view, name='details'),
views.py
def details_view(request, advertisementid):
advertisement_data = Advertisement.objects.get(id=advertisementid)
return render(request, "details.html", {"advertisement_data": advertisement_data})
def profile_view(request, userid):
advertisements = Advertisement.objects.filter(user__id=userid)
return render(request, "profile.html", { 'advertisements': advertisements } )
details.html (from where I want to resolve to the users profile)
<a href="{% url 'profile' userid=advertisement_data.user.id %}" style="text-decoration:none;">
<input type="submit" class="details-btn-profile" value="Profile"></a>
<a href="{% url 'chat_view_with_toid' advertisementid=advertisement_data.id %}"
style="text-decoration:none">
<input type="submit" class="details-btn-contact" value="Kontakt"></a>
main.html
<a href="{% url 'details' advertisementid=advertisement.id %}">
<img src="{% static advertisement.image.url %}" alt="Image"/></a>
When I click on button class="details-btn-profile"
Django gives me this error:
Reverse for 'details' with no arguments not found. 1 pattern(s) tried: ['details/(?P(\d+))/$']
Why does it resolve to details ? Any ideas ?
Upvotes: 0
Views: 872
Reputation: 1007
Sorry for wasting your time, I found my mistake. On profile.html I had this HTML-Code:
<a href="{% url 'details' %}" class="announce-hedline"><h3>BMW 320i Limousine</h3></a>
So "{% url 'details' %}"
can not be resolved because of missing the advertisementid which it needs to be resolved.
I searched for mistakes in the wrong place.
Thank you all for your help !
Upvotes: 0
Reputation:
when you click the button you send form where action wrong may be empty attr action
something like it:
<form action="">
you need set it:
<form action="{% url 'profile' userid=advertisement_data.user.id %}">
<!-- ^^^^^^^^^^^^^-->
or if you want to go link by click the just change type
<input type="button" class="details-btn-profile" value="Profile">
<!-- ^^^^^^^^^^-->
Upvotes: 1
Reputation: 1802
The url name chat_view_with_toid
doesn't seem to exist in your urls.py.
Upvotes: 0