DeleteView - 通过 Popup 确认 windows
DeleteView - confirm by Popup windows
我想问你,如果你知道,这里有一些要点或解决方案如何通过 Popup bootstrap window 使用 DeleteView class 确认删除项目。所以我不会使用template_name
,而是在当前页面弹出windows。
非常感谢你所做的一切...!!!
更准确地说
我的 index.html 页面
中有这个按钮
<button type="button" class=" ml-1 btn btn-outline-dark my-2 my-sm-0" data-toggle="modal" data-target="#exampleModal">
In
</button>
我这里有删除模式
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Are you sure to delete this?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
<div class="modal-footer">
<a href="#" class="button btn btn-primary">Yes</a>
<button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
这是我的 views.py 删除
class ItemDeleteView(DeleteView):
model = Item
# template_name = 'index.html'
success_url = reverse_lazy('index')
login_url = '/accounts/login/'
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs)
而且我不知道该怎么办。现在...谢谢
最佳选择是 Javascript,但您可以改为重新定义 DeleteView 的 get 方法 class :
将其添加到您的 class
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs)
基本上,Deleteview 需要 post 请求才能触发,这有点麻烦,但效果很好。
在您的模板中,将其放在模态窗口或弹出窗口中
<form method="POST" action="{% url "your_delete_url_name" %}">
{% csrf_token %}<input type="submit" value="DELETE">
</form>
不要忘记 URL
中的对象 ID
我想问你,如果你知道,这里有一些要点或解决方案如何通过 Popup bootstrap window 使用 DeleteView class 确认删除项目。所以我不会使用template_name
,而是在当前页面弹出windows。
非常感谢你所做的一切...!!!
更准确地说 我的 index.html 页面
中有这个按钮 <button type="button" class=" ml-1 btn btn-outline-dark my-2 my-sm-0" data-toggle="modal" data-target="#exampleModal">
In
</button>
我这里有删除模式
<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Are you sure to delete this?</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
</div>
<div class="modal-footer">
<a href="#" class="button btn btn-primary">Yes</a>
<button type="button" class="btn btn-danger" data-dismiss="modal">No</button>
</div>
</div>
</div>
</div>
</div>
这是我的 views.py 删除
class ItemDeleteView(DeleteView):
model = Item
# template_name = 'index.html'
success_url = reverse_lazy('index')
login_url = '/accounts/login/'
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs)
而且我不知道该怎么办。现在...谢谢
最佳选择是 Javascript,但您可以改为重新定义 DeleteView 的 get 方法 class :
将其添加到您的 class
def get(self, request, *args, **kwargs):
return self.post(request, *args, **kwargs)
基本上,Deleteview 需要 post 请求才能触发,这有点麻烦,但效果很好。
在您的模板中,将其放在模态窗口或弹出窗口中
<form method="POST" action="{% url "your_delete_url_name" %}">
{% csrf_token %}<input type="submit" value="DELETE">
</form>
不要忘记 URL
中的对象 ID