Consider the code below (in urls.py):
router = DefaultRouter()
router.register('my-endpoint', MyViewSet, basename='mybasename')
urlpatterns = [
path('api/v1/', include(router.urls)),
path('api/token/', TokenObtainPairView.as_view(), name='token_obtain_pair'),
path('api/token/refresh/', TokenRefreshView.as_view(), name='token_refresh'),
]
This code is valid but the 2 endpoints (TokenObtainPairView and TokenRefreshView) not appear in the Root API (DRF)
Then, I tried to register both endpoints of django-rest-frakmework-simplejwt on the router:
router = DefaultRouter()
router.register('my-endpoint', MyViewSet, basename='mybasename'),
router.register('api/token/', TokenObtainPairView.as_view(), basename='token_obtain_pair')
router.register('api/token/refresh/', TokenRefreshView.as_view(), basename='token_refresh')
# Other way:
# router.register('api/token/', TokenObtainPairView, basename='token_obtain_pair')
# router.register('api/token/refresh/', TokenRefreshView, basename='token_refresh')
urlpatterns = [
path('api/v1/', include(router.urls))
]
And then when I run, the following error occurs:
File "/home/sidon/dev/boticario-teste/boticashback/boticashback/urls.py", line 32, in <module>
path('api/', include(router.urls)),
File "/home/sidon/miniconda3/envs/botcash/lib/python3.8/site-packages/rest_framework/routers.py", line 78, in urls
self._urls = self.get_urls()
File "/home/sidon/miniconda3/envs/botcash/lib/python3.8/site-packages/rest_framework/routers.py", line 339, in get_urls
urls = super().get_urls()
File "/home/sidon/miniconda3/envs/botcash/lib/python3.8/site-packages/rest_framework/routers.py", line 237, in get_urls
routes = self.get_routes(viewset)
File "/home/sidon/miniconda3/envs/botcash/lib/python3.8/site-packages/rest_framework/routers.py", line 153, in get_routes
extra_actions = viewset.get_extra_actions()
AttributeError: type object 'TokenObtainPairView' has no attribute 'get_extra_actions'