0

I am getting these urls with django's get_resolver() function for a class:

^api/asset_management/^^get_assets/$
^api/asset_management/^^get_assets\.(?P<format>[a-z0-9]+)/?$
^api/asset_management/^^get_assets/(?P<pk>[^/.]+)/$
^api/asset_management/^^get_assets/(?P<pk>[^/.]+)\.(?P<format>[a-z0-9]+)/?$

I also want the name of the method where each of these url is redirected e.g. Get, Post etc. The class is a simple ModelViewSet and is registered by the DefaultRouter.

3
  • It might not be possible to get a 100% correct result here since the method isn't actually stored in the URL pattern but in the view itself and views can be any Python function / method. Answers that support only class based views (builtin generic views from Django or from known packages like Django Rest Framework) should be possible though. Commented Dec 12, 2024 at 10:19
  • My views are of type viewsets.ModelViewSet which is imported from rest_framework. I am only defining the get_queryset method while the rest is the default functionality. If this information is not stored anywhere then since similar urls are generated for all the ModelViewSet is it possible to parse the url string to determine the endpoint? Commented Dec 12, 2024 at 10:30
  • If you're using DRF it should be possible to get the information from the view class, my comment focuses more on function based views (and class based views which either don't inherit from builtin ones or modify the builtin quite a lot) Commented Dec 12, 2024 at 10:40

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.