I've been studying the viewset and router docs for Django and I can't figure out how to set up a route to access the method on a viewset.
For example, here is my urls.py:
from rest_framework.routers import DefaultRouter
from users.views import (UserViewSet, testing)
router = DefaultRouter()
router.register(r"users", UserViewSet, basename="users")
urlpatterns = [
path('testing', testing)
]
And then this is my views file in my user directory
@csrf_exempt
class UserViewSet:
def create(self):
return JsonResponse({
'the create endpoint'
})
@csrf_exempt
def testing(request):
return JsonResponse({
"title": "My json res"
})
Using postman, I can hit the endpoint example.com/testing and have the json response logged out. However, I try to hit example.com/users/create and I get a 404. I thought the basename propery when registering the viewset with the router would group all of the methods inside that class under that route path and then the methods would all be their own endpoint. Am I thinking about this incorrectly? Any help would be lovely as I am new to Django. I've mostly done Express and Laravel. Thanks!