[Django]-Setting up router with APIView and viewset in Django Rest Framework

9👍

Something like this should work.

from post.api.views import UniquePostViewSet
from django.urls import path, include
from rest_framework.routers import DefaultRouter

from post.api.views import FileUploadView

router = DefaultRouter()
router.register('UniquePost', UniquePostViewSet, base_name='uniquepostitem')

urlpatterns = [
    path('demo',FileUploadView.as_view(),name='demo'),  
]

urlpatterns += router.urls

0👍

urls.py

router = routers.DefaultRouter()
router.register(r'users', UsersViewSet, basename ='users')

This happens when there is no queryset attribute in the viewset.

Leave a comment