我只是想打電話從模板視圖功能可按,我已經看到了,我有相反的功能做到這一點。我想傳遞一個參數給視圖函數,但我不想在url中顯示它。可能嗎?這裏是我的代碼和錯誤:Django的反向找不到
urls.py
url(r'^perfil/deleteDownloadedTrack/$','principal.views.delete_downloaded_track', name='delete_downloaded_track'),
views.py
def delete_downloaded_track(request, track):
...
return HttpResponseRedirect(reverse('profile_detail'))
template.html
{% for track in downloadedTracks %}
<tr>
<td>
{{track.name}}
</td>
<td>
<div class="botoForm" onclick="location.href='{% url "principal.views.delete_downloaded_track" track %}'"> Eliminar </div>
</td>
{% endfor %}
和錯誤:
Reverse for 'principal.views.delete_downloaded_track' with arguments '(<DownloadedTrack: DownloadedTrack object>,)' and keyword arguments '{}' not found.
謝謝!
您URLPATTERN需要包括一個部件以捕獲(大概)的DownloadedTrack實例的ID,那麼你的{%URL%}標籤需要軌道 - > track.id。請參閱:https://docs.djangoproject.com/en/dev/topics/http/urls/ – AdamKG