'Get post() function from the view function returned by resolve()

I defined a class based on rest_framework.views.APIView and added it as a view to some url. For example like:

from rest_framework.views import APIView
from rest_framework.response import Response
from django.urls import path

class MyApi(APIView):

    def post(self, request):
        # Do something with the request
        print(request.data)
        return Response(status=200)


path('my-url', MyApi.as_view())

In another file, I want to access the post() function of that class, but I only know the url. So I use the django.urls.resolve() function to get the view function.

from django.urls import resolve
view, args, kwargs = resolve(url)

However, I don't want to obtain the view function, but the underlying post() function that I defined in the API-Class.

Is there any option to get that function while only knowing the url?

I want to avoid building a lookup for every possible url.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source