删除页面没有太多的内容和功能
def del_view(self, request,pk,*args,**kwargs): """ 处理删除表弟 :param request: :param pk: :return: """ obj = self.model_class.objects.filter(pk=pk).first() if not obj: return HttpResponse(‘该内容不存在‘) if request.method == ‘GET‘: return render(request, ‘stark/delete.html‘, {‘obj‘: obj, ‘cancel_url‘: self.reverse_changelist_url(*args,**kwargs)}) self.model_class.objects.filter(pk=pk).delete() return redirect(self.reverse_changelist_url(*args,**kwargs))
前端html
{% extends ‘layout.html‘ %} {% block content %} <form method="post"> {% csrf_token %} <h4 class="page-header alert-danger">注意以下与{{ obj }}相关的信息都将被删除,请确认是否删除?</h4> <a href="{{ cancel_url }}" class="btn btn-primary">取消</a> <input type="submit" class="btn btn-danger" value="确认"> </form> {% endblock %}
原文地址:https://www.cnblogs.com/shenjianping/p/10912569.html
时间: 2024-10-07 04:38:04