I'm trying to create a link <a> that redirects me to an url of a view DeleteView. I want that link to be in the template of my app. By clicking on that link you will get redirected to the url of the DeleteView.
Here's the DeleteView:
class imagenDelete(DeleteView):
model = imagen
def get_id(self, request):
getall = imagen.objects.all()
Here's the urls.py:
urlpatterns = [
path('', views.galeria, name='galeria'),
path('delete/<int:pk>', views.imagenDelete.as_view(), name='deletegaleria'),
]
Here's the link im trying to create in the template of my App:
<a style="font-size: 3rem;" href="{% url 'deletegaleria' pk %}">Click to delete</a>
The problem is that in the url i must pass the id of the image that you want to delete. If i'd write it like this {% url 'deletegaleria' 14 %} it works, te link is shown in the template and it redirects you to the url to delete the image with id = 14.
If i'd do it like this:
{% for on in getall %}
<a style="font-size: 3rem;" href="{% url 'deletegaleria' o.id %}">Click to delete</a>
{% endfor %}
This doesn't give me any error but doesn't show the link in the template.
And if i do this way {% url 'deletegaleria' pk %} which is basically no iterating i get the next error:
Reverse for 'deletegaleria' with arguments '('',)' not found. 1 pattern(s) tried: ['galeria/delete/(?P[0-9]+)$']