X
X
Xmahopnya2020-02-17 13:44:38
Django
Xmahopnya, 2020-02-17 13:44:38

How to execute a method from Class Based Views on opening a Django page?

Good afternoon, I'm trying to deal with CBV.
I want the test_http_response function to be processed as soon as a request for the URL is made, but it doesn’t work for some reason. Tell me the right way, please.

class PostDetailView(DetailView):
    model = Post
    def test_http_response(self, request, pk):
        HttpResponse("test response")
        print("test")

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2020-02-17
@Xmahopnya

class PostDetailView(DetailView):
    model = Post
    def dispatch(self, request, *args, **kwargs):
        resp = HttpResponse("test response")
        print("test")
        return resp

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question