I Have just started with django-rest-framework. Pretty enthousiastic about it, except for the fact there are very little examples available. getting the api working is going great, but all the extra's is a puzzle. (adding extra custom fields etc.)
Now I wonder how you can restrict the allowed_methods in for example a ListView or a DetailView. Adding this to the class in the views.py like I read somewhere as an answer... does not seem to have any effect:
allowed_methods = ('GET',)
The Django REST Framework(DRF) is a framework for quickly building robust REST API's. However when fetching models with nested relationships we run into performance issues. DRF becomes slow. This isn't due to DRF itself, but rather due to the n+1 problem.
Django is the web development framework in python whereas the Django Rest Framework is the library used in Django to build Rest APIs. Django Rest Framework is especially designed to make the CRUD operations easier to design in Django. Django Rest Framework makes it easy to use your Django Server as an REST API.
Django REST Framework is only necessary if you're building a RESTful API; An HTTP service that reads and writes data, usually as JSON payloads. Services are typically created to allow external clients such as mobile apps, single page applications (React, Angular, etc.) or 3rd parties to gain access to your data.
If you are using ModelViewSet and still want to restrict some methods you can add http_method_names
.
Example:
class SomeModelViewSet(viewsets.ModelViewSet):
queryset = SomeModel.objects.all()
serializer_class = SomeModelSerializer
http_method_names = ['get', 'post', 'head']
Once you do this, get
, post
and head
will be allowed. But put
, patch
and delete
will not be allowed.
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