Answer the question
In order to leave comments, you need to log in
Django. How to return to the previous page?
I have a django controller image_delete. I use it on multiple pages. I need the controller to take me back to the previous page after deleting the image. But I am getting an error. what is the problem? How to fix it?
views.py
class ImageDelete(DeleteView):
model = Picture
template_name = 'adminapp/pet/pet_image_delete.html'
@method_decorator(user_passes_test(lambda x: x.is_superuser))
def dispatch(self, *args, **kwargs):
return super().dispatch(*args, **kwargs)
def get_success_url(self):
return HttpResponseRedirect(request.META.get('HTTP_REFERER'))
path('delete/image/<int:pk>/', adminapp.ImageDelete.as_view(model=Picture), name='image_delete')
Answer the question
In order to leave comments, you need to log in
def get_success_url(self):
should return the url and not the response. Just try
def get_success_url(self):
return request.META.get('HTTP_REFERER')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question