0

in function view:

def view(request):
    # do something with request
    response = render(request, 'view.html')
    # do something with response
    return response

but now I have a View class:

class ArticleDeleteView(View):
    pass


# or even something more complicated
class ArticleDeleteView(LoginRequiredMixin, UserPassesTestMixin, DeleteView):
    pass

which function shall I overwrite to access to the response?


sorry that it may seems a silly question to you, but I looked through the docs and failed to find an answer.


thanks for all suggestions in comment. here's why I need to access to the response. Conditional Django Middleware (or how to exclude the Admin System)

I am building a specific type of 'middleware', for certain class based view, they are not actually middleware since they are not called for each request. I need to access to the response in order to do something before and after the response then return it, therefore I much would like to know which function generate response.

Weilory
  • 2,621
  • 19
  • 35
  • What do you want to do with `response` ? – Lucas Grugru Oct 23 '22 at 15:23
  • 1
    Here is useful [site](https://ccbv.co.uk/projects/Django/4.0) to inspect all available methods of a class. – Ankit Tiwari Oct 23 '22 at 15:27
  • 1
    For [**View**](https://ccbv.co.uk/projects/Django/4.0/django.views.generic.base/View/), [**LoginRequiredMixin**](https://ccbv.co.uk/projects/Django/4.0/django.contrib.auth.mixins/LoginRequiredMixin/), [**UserPassesTestMixin**](https://ccbv.co.uk/projects/Django/4.0/django.contrib.auth.mixins/UserPassesTestMixin/), [**DeleteView**](https://ccbv.co.uk/projects/Django/4.0/django.views.generic.edit/DeleteView/), – Ankit Tiwari Oct 23 '22 at 15:28

1 Answers1

1

The easiest answer is: you don't. The View classes tend to be uncomplicated enough to be easily rewritten as a custom view which inherently gives you access to the response.

However if you insist I guess one of the functions you could override is the following: as_view, dispatch or setup as the request function goes through all of them. Sadly I couldn't find any mention of the one that was intended for that purpose.

Blye
  • 619
  • 4
  • 20