Django嘗試錯誤的url模式,但我找不到我的錯誤。爲什麼Django嘗試錯誤的url模式?
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(從那裏我想解析爲用戶配置文件)
<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>
當我在按鈕class="details-btn-profile"
點擊Django的給了我這個錯誤:
Reverse for 'details' with no arguments not found. 1 pattern(s) tried: ['details/(?P(\d+))/$']
爲什麼它解決細節?有任何想法嗎 ?
圍繞給定的HTML代碼有沒有一種形式? –
不,但 Coder949
表單將控制任何提交按鈕的行爲。如果沒有任何形式,我不確定會發生什麼。可能會有一個默認的默認導致GET到相同的URL和給定的錯誤。 –