首页 > 解决方案 > 有没有办法从 html 文档中的数据库中删除对象?(django)

问题描述

视图.html

<th><button id={{p.id}} onclick="Delete(this.id)" class="btn btn-outline-danger">Delete</button></th>
  <script>
    function Delete(row_id){
      document.getElementById(row_id).remove();
      {{dogss.objects.filter(id=1)}.delete()}} //I wanted this to happen, but it's not working
    }
  </script>
</tr>

视图.py

def view(response):
return render(response, "main/view.html", {"dogs": Dog.objects.filter(user=response.user), "dogss": Dog})

我知道我可以使该按钮与 .py 文件交互,并且从那里它可能会起作用。但我很好奇为什么这不起作用?

标签: javascriptdjangosqlitedjango-models

解决方案


推荐阅读