Friday, 17 February 2023

DRF: API root view doesn't list my APIs for some reasons

I have the following urls.py for an app named service where I register API endpoints:

from .views import AccessViewSet, CheckViewSet

app_name = "api"

router = DefaultRouter()

router.register(r"access/(?P<endpoint>.+)", AccessViewSet, basename="access")
router.register(r"check/(?P<endpoint>.+)", CheckViewSet, basename="check")


urlpatterns = [
    path("", include(router.urls)),
]

Below is my project's urls.py where I use it:

from django.conf import settings
from django.contrib import admin
from django.urls import include, path

import service.urls as service_urls

urlpatterns = [
    # ...
    path("service/", include('service.urls')),
]

The APIs themselves are functioning properly, but I am having trouble making them work with DRF's default API root view. The view is displaying an empty list of available endpoints. I'm not sure, but this issue may be related to the regular expressions I'm using when registering endpoints, such as r"access/(?P<endpoint>.+). If this is indeed the problem, how can I resolve it?"



from DRF: API root view doesn't list my APIs for some reasons

No comments:

Post a Comment