title: PUT and Delete Request in Django rest framework
body: <p>I am new to Django, I was wondering How to code PUT request and Delete method in my Django REST API Project.</p>
  
  <p>I have tried to follow with many tutorials, but none working with my kind of code.</p>
  
  <p>The code I tried looks like this</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>def put(self, request, pk):
          snippet = self.get_object(pk)
          serializer = UserSerializers(snippet, data=request.data)
          if serializer.is_valid():
              serializer.save()
              return Response(serializer.data)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)</code></pre>
  </div>
  </div>
  </p>
  
  <pre><code>def delete(self, request, pk):
      snippet = self.get_object(pk)
      snippet.delete()
      return Response(status=status.HTTP_204_NO_CONTENT)
  </code></pre>
  
  <p>But getting message method not allowed</p>
  
  <p>The following is my Models.py</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from django.db import models
  
  
  class Users(models.Model):
      user_id = models.AutoField(primary_key=True)
      name = models.CharField(max_length=50)
      profile_name = models.CharField(max_length=30)
      profile_picture = models.CharField(max_length=1000)
      phone = models.CharField(max_length=15)
      email = models.EmailField()
      password = models.CharField(max_length=25, default='')
  
      def __str__(self):
          return self.name</code></pre>
  </div>
  </div>
  </p>
  
  <p>The following is my serializers.py</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from rest_framework import serializers
  from .models import Users
  from .models import UserPost
  
  
  class UserSerializers(serializers.ModelSerializer):
      class Meta:
          model = Users
          fields = '__all__'
  
  
  class UserDetailSerializer(serializers.ModelSerializer):
      class Meta:
          model = Users
          fields = '__all__'
  
  
  class UserPostSerializers(serializers.ModelSerializer):
      class Meta:
          model = UserPost
          fields = '__all__'</code></pre>
  </div>
  </div>
  </p>
  
  <p>The following code contains my Views.py </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from django.http import Http404
  from rest_framework.response import Response
  from rest_framework.views import APIView
  from rest_framework import status
  from .models import Users
  from .models import UserPost
  from .serializers import UserSerializers, UserPostSerializers
  
  
  class UsersList(APIView):
  
      def get(self, request):
          User_details = Users.objects.all()
          serializer = UserSerializers(User_details, many=True)
          return Response(serializer.data)
  
      def post(self, request):
          serializer = UserSerializers(data=request.data)
          if serializer.is_valid():
              serializer.save()
              return Response(serializer.data, status=status.HTTP_201_CREATED)
          return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
  
  
  class UserDetail(APIView):
      def get_object(self, pk):
          try:
              return Users.objects.get(pk=pk)
          except Users.DoesNotExist:
              raise Http404
  
      def get(self, request, pk):
          snippet = self.get_object(pk)
          serializer = UserSerializers(snippet)
          return Response(serializer.data)
  
      class UserViewSet(viewsets.ModelViewSet):
          queryset = Users.objects.all()
          serializer_class = UserSerializer
  
          @action(methods=['put'], detail=False)
          def filter_by_something(self, request):
              something = request.data.get('that_something')
              queryset = Users.objects.filter(something__exact=something)
              return Response(self.get_serializer(queryset, many=True).data)</code></pre>
  </div>
  </div>
  </p>
  
  <p>The following code contains urls.py</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>from sys import path
  
  from django.urls import include
  from rest_framework.urlpatterns import format_suffix_patterns
  from app import views
  from django.conf.urls import url
  from django.contrib import admin
  
  from rest_framework import routers
  router = routers.DefaultRouter()
  
  
  
  router.register('user_details', UserDetailViewSet)
  urlpatterns = [path('api/', include(router.urls)), ...]
  urlpatterns = [
  
      url(r'^admin/', admin.site.urls),
      url(r'^User_details/', views.UsersList.as_view()),
      url(r'^User_details/(?P&lt;pk&gt;[0-9]+)/', views.UserDetail.as_view()),
      url(r'^userpost_details/', views.UsersPostList.as_view()),
  
  ]
  urlpatterns = format_suffix_patterns(urlpatterns)</code></pre>
  </div>
  </div>
  </p>