Django DeleteView没有确认

时间:2017-05-27 19:20:09

标签: django confirmation django-generic-views

我想通过DeleteView删除一个对象。

我的views.py看起来像这样:

class HabitDelete(DeleteView):
model = Habit
success_url = reverse_lazy('renderOverview')
template_name = 'overview/habit_delete_confirm.html'

我的urls.py看起来像这样:

    url(r'^details/(?P<pk>\w{0,50})/delete/$', overview_views.HabitDelete.as_view(), name='deleteHabit'),

我的模板:

    {% block content %}
  <div class="container custom-div-habit-detail">
    <h1 class="custom-title-label">{{habit.title}}</h1>
    <!-- <a href="{% url 'deleteHabit' habit.id %}">
      <span class="glyphicon glyphicon-trash custom-glyphicon-trash"></span>
    </a> -->
    <form action="{% url 'deleteHabit' pk=habit.id %}" method="POST" class="custom-form-trash">
      {% csrf_token %}
      <button type="submit" class="btn btn-default custom-btn-trash">
        <span class="glyphicon glyphicon-trash custom-glyphicon-trash"></span>
      </button>
    </form>
    <br>
    <br>
    <p class="custom-trigger-label custom-padding-top-30">{{habit.trigger}}...<p>
    <p class="custom-routinebehavior-label">{{habit.existingroutine}}<p><br>
    <p class="custom-trigger-label">I will...</p>
    <p class="custom-routinebehavior-label">{{habit.targetbehavior}}</p><br>
    <p> <img src="{{ habit.image_url }}" class="img-responsive custom-image-detail" width="100"></p>
    <br>
    <a class="btn btn-default custom-tab-item" href="/overview">
      <span class="glyphicon glyphicon-chevron-left"></span>
      <span class="tab-label">Go back</span>
    </a>

    <button class="btn btn-default custom-tab-item" id="myform">
      <span class="glyphicon glyphicon-ok"></span>
      <span class="tab-label">Let's go</span>
    </button>
  </div>
{% endblock %}

,文件夹templates / overview包含habit_delete_confirm.html。 我的目标&#39;习惯&#39;将被删除成功,但我不知道为什么我没有像往常一样获得确认模板。

0 个答案:

没有答案