I'm trying to make an APIView with the Django Rest Framework. When I associate the view with the url, I got this error :
AssertionError: basename argument not specified, and could not automatically determine the name from the viewset, as it does not have a .queryset attribute.
Here is mys APIView :
class ExampleView(APIView):
authentication_classes = (SessionAuthentication, BasicAuthentication)
permission_classes = (IsAuthenticated,)
def get(self, request, format=None):
content = {
'user': unicode(request.user), # `django.contrib.auth.User` instance.
'auth': unicode(request.auth), # None
}
return Response(content)
And the router :
router = routers.DefaultRouter()
router.register('api/example', views.ExampleView.as_view())
So, what's wrong ? Thank you !
You just need to add the path to your urlpatterns
. Routers are used with viewsets.
from django.urls import path
app_name = 'example'
urlpatterns = [
path('api/example', views.ExampleView.as_view(), name='example')
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With