Reputation: 2316
So, I have a view that inherits from APIView, I've defined get, post and delete methods.
My urls.py:
path('projects/', projects.ProjectView.as_view()),
path('projects/create/', projects.ProjectsView.as_view()
But right now I can make a request with any method accessing these API's. For example, I can create a project going to 'projects/' and I can delete a project going to 'projects/create/'.
Is there a way to specify what methods I wanna use for a specific url? When a user goes to 'projects/' I want only the 'get' method to be allowed for this url.
Upvotes: 1
Views: 328
Reputation: 1433
On classy way to do it is to inherit from generic-view
Your ProjectView
should inherit from RetrieveAPIView
and ProjectsVIew
from CreateAPIView
And you could probably rename your views to something more explicit.
Upvotes: 2