A
A
Artem2019-10-15 10:44:10
Django
Artem, 2019-10-15 10:44:10

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'))

If I prescribe "self" before "request", then I get the error "quote_from_bytes () expected bytes"
urls.py
path('delete/image/<int:pk>/', adminapp.ImageDelete.as_view(model=Picture), name='image_delete')

Screenshot error.
5da578b3de98f551069773.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yura Khlyan, 2019-10-15
@MAGistr_MTM

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 question

Ask a Question

731 491 924 answers to any question