[Answered ]-HttpResponseRedirect does not call another view

1👍

The problem is that when your browser sends a POST request and receives a redirect, it will follow the redirect with a GET request.

  • You POST to viewStore.
  • viewStore redirects you to the deleteStore view
  • Your browser GETs the deleteStore view
  • deleteStore does not delete because it’s a GET request, then redirects you to the viewStore

You should change the form in your template so that it posts directly to the deleteStore view.

1👍

you must to return the HttpResponseRedirect. That is your error

0👍

You never return the responses, you just create them. Simply return the responses.

def viewStore(request):
    if request.POST:
        if request.POST.get('delete_selected'):
            id = int(request.POST.get('check'))
            return HttpResponseRedirect('/dataInfo/store_view/delete/%d/' %id)
    view_store = Store.objects.all()
    context = {'view_store': view_store}
    return render(request, 'dataInfo/store_view.html', context)

def deleteStore(request):
    if request.POST.get('delete_selected'):
        Store.objects.filter(pk__in=request.POST.get('check')).delete()
    return HttpResponseRedirect('/dataInfo/store_view/')
👤Sayse

Leave a comment