I am newbie on DRF so I wonder if there a "elegant" way to add more endpoints to API Root. I have an endpoint to manage my users and another to manage their posts, but on http://localhost:8000/api/ only profiles appears. I search for some solutions that implies change the URL but I don't want that. For example my current endpoint to get all posts is localhost:8000/api/posts that looks fine. I don't want something like api/posts/posts or similar. Is there any alternative?
{
"profiles": "http://localhost:8000/api/profiles/"
}
main urls.py
urlpatterns = [
path('docs/', schema_view.with_ui('swagger',
cache_timeout=0), name='schema-swagger-ui'),
path('admin/', admin.site.urls),
path('api/', include('profiles.urls')),
path('api/', include('posts.urls')),
path('api/', include('comments.urls')),
path('api/', include('private_messages.urls')),
]
userprofile urls.py
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from rest_framework_simplejwt import views as jwt_views
from .views import UserProfileViewSet
router = DefaultRouter()
router.register('profiles', UserProfileViewSet)
urlpatterns = [
path('', include(router.urls)),
path('auth/login', jwt_views.TokenObtainPairView.as_view()),
path('auth/refresh', jwt_views.TokenRefreshView.as_view()),
]
posts urls.py
from django.urls import path, include
from rest_framework.routers import DefaultRouter
from .views import PostViewSet, PostByAuthorViewSet
router = DefaultRouter()
router.register('posts', PostViewSet)
urlpatterns = [
path('posts-by-author/<author_id>', PostByAuthorViewSet.as_view()),
path('', include(router.urls))
]