Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

103
Views
How to delete an entry from queryset in django html template without refresing page?

On my HTML template, I am printing a list of my QuerySet that I passed from views.py in Django. I want users to delete an entry from the list without refreshing the page. How do I do that?

urls.py - path("del_trans/<int:trans_num>", views.delete_transaction, name="delete_transaction")

views.py

def delete_transaction(request, trans_id):
    user = User.objects.get(username=request.user)

    transaction = Transaction.objects.get(ruser=user, id=trans_id)

    transaction.delete()

    return HttpResponse(status=204)

trans.html

<tr id="trans-{{t.id}}">
    <td>{{ t.name }}</td>
        
    <td><button class="btn" onclick="delete_trans({{t.id}})"><span style="cursor:pointer;
            color:blue;
            text-decoration:underline;">Delete</span></button></td>
</tr>

index.js

function delete_trans(id) {
    fetch(`/del_trans/${id}`, {
        method: 'PUT',
        body: JSON.stringify({
            trans_id: id
        })
    });

    document.querySelector('#trans-' + id).style.display = 'none';
}
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!