I need to delete data on click of a button in django here's my view page
def hierarchy(request):
from .models import environments
if request.method == 'POST':
env = environments()
# environments.objects.filter(Mainline = '').delete()
mainline = environments.objects.filter(Mainline = True)
for obj in mainline:
environments.objects.filter(ParentName=obj.Name).delete()
path = obj.URL
path = path + 'environments.csv'
df = open(path, 'r')
for line in df:
row = line.split(',')
env = environments(Name=row[1], ParentName=obj.Name)
env.save()
env = list(environments.objects.values_list('ParentName','Name'))
return render(request, 'hello/hierarchy.html',{'Child': env})
here's my button code
<button type="submit" class="btn btn-outline-primary" onClick="refreshPage()"
style="margin-left:10px; position: absolute;
z-index: 1; margin-top: 5px">Update Details</button>
<script>
function refreshPage(){
window.location.reload();
}
</script>
button onclick of that button data should get deleted. this button works as a refresh button. So even if I do not click on the button only do page refresh data get deleted