Error DeleteView

1

Hi, I have a problem with my DeleteView in Django 1.8, I get this error:

  

TemplateDoesNotExist at /eliminar_tipo_almacen/38/appkardex/tipo_almacen_confirm_delete.html

views.py:

from django.views.generic import ListView, UpdateView, DeleteView

class EliminarTipoAlmacen(DeleteView):
    model = Tipo_almacen
    success_url = reverse_lazy('lista_tipo_almacen')



urls.py

url(r'^eliminar_tipo_almacen/(?P<pk>\d+)/$', views.EliminarTipoAlmacen.as_view(), name='eliminar_tipo_almacen'

list_type_almace.html:

<table class="table">
  <thead>
    <th>Nombre</th>
    <th>Acciones</th>
  </thead>

  <tbody>
    {% for data in lista_tipo_almacen %}
    <tr>
      <td>{{ data.descripcion }}</td>
      <td>
       <a href="{% url 'editar_tipo_almacen' data.pk %}"><span class="glyphicon glyphicon-file">Editar </span></a>
       <a href="{% url 'eliminar_tipo_almacen' data.pk %}"><span class="glyphicon glyphicon-trash">Borrar </span></a>

     </td>
   </tr>
   {% endfor %}
</tbody>

tipo_almacen_confirm_delete.html:

{% extends "main.html" %}

{% block contenido %}
  <form action="" method="post">{% csrf_token %}
      <p>Quieres eliminar "{{ object }}"</p>
      <input type="submit" value="Confirmar" />
  </form>

{% endblock %}

Waiting for your collaboration

    
asked by Andres Vilca 27.01.2016 в 02:17
source

2 answers

2

you need to pass the name of the template in your DeleteView class

template_name = "eliminartipoalmacen.html"

create that template that serves to confirm the elimination

    
answered by 10.03.2016 в 00:50
1

In the code fragments you do not say how lista_tipo_almacen is resolved. Apparently you intend to call a template that is named (although you do not call the template, but in plain sight) , so you should have a path in your urls.py file that resolves that call .

from django.views.generic import TemplateView
url(r'^lista/$', TemplateView.as_view(template_name='lista_tipo_almacen.html')),

Actually, you are calling the function that returns the list type store, then this is the way you should call the function:

url(r'^lista/$', 'lista', name='lista_tipo_almacen'),

Or if it's a class-based view, it would be something like that

from .views import Lista:
url(r'^lista/$', Lista.as_view(), name='lista_tipo_almacen'),

In any case, the reverse_lazy function resolves a defined route in your search patterns, does not call a template directly.

    
answered by 28.01.2016 в 05:23