Home > Mobile >  how to reverse page after deleting any data in django?
how to reverse page after deleting any data in django?

Time:12-14

i wanted to redirect my page to index after deleting row so i use `

return HttpResponseRedirect(reverse('index'))

to reverse . i wanted thishttp://127.0.0.1:8000/indexbut it is showinghttp://127.0.0.1:8000/index/index` what is the proble please help me.

this is my view.py `

def index(request):
    return render(request, "card/index.html")

def delete(request, id):
    dishes = dish.objects.get(id=id)
    dishes.delete()
    return HttpResponseRedirect(reverse('index'))

this is urls.py

    path('index', views.index, name="index"),
    path('check', views.check, name="check"),
    path('delete/<int:id>', views.delete, name='delete'),

`

CodePudding user response:

Try using the conventional method of reverse('app_name:url_name').

2nd method: Try passing the path directly in reverse like reverse('/index')

CodePudding user response:

from django.shortcuts import render, redirect

def index(request):
    return render(request, "card/index.html")

def delete(request, id):
    dishes = dish.objects.get(id=id)
    dishes.delete()
    return redirect("/index/")
  • Related