You can do that using ApiView also:
details: https://www.django-rest-framework.org/tutorial/3-class-based-views/

class SnippetDetail(APIView):
    """
    Retrieve, update or delete a snippet instance.
    """
    def get_object(self, pk):
        try:
            return Snippet.objects.get(pk=pk)
        except Snippet.DoesNotExist:
            raise Http404

    def get(self, request, pk, format=None):
        snippet = self.get_object(pk)
        serializer = SnippetSerializer(snippet)
        return Response(serializer.data)

    def put(self, request, pk, format=None):
        snippet = self.get_object(pk)
        serializer = SnippetSerializer(snippet, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    def delete(self, request, pk, format=None):
        snippet = self.get_object(pk)
        snippet.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)

urlpatterns = [
    path('snippets/<int:pk>/', views.SnippetDetail.as_view()),]


On Mon, Sep 23, 2019 at 1:54 PM Shakil Ahmmed <shakilfci...@gmail.com>
wrote:

> Please Can You Give me some Exapmle?
>
> On Mon, Sep 23, 2019, 1:39 PM Abu Yusuf <yu...@binate-solutions.com>
> wrote:
>
>> Check this:
>> https://docs.djangoproject.com/en/2.2/ref/class-based-views/flattened-index/#formview
>>
>> On Mon, Sep 23, 2019 at 12:13 PM Shakil Ahmmed <shakilfci...@gmail.com>
>> wrote:
>>
>>> How Can i Use Those Methods In One Class Base View ['get', 'post',
>>> 'put', 'patch', 'delete', 'head', 'options', 'trace']
>>>
>>> Example:
>>>
>>> from django.views import View
>>>
>>> class Home(View):
>>>       def get(self, request, *args, **kwargs):
>>>
>>>         return HttpResponse('Hello, World!')
>>>
>>> def post(self, request, *args, **kwargs):
>>>
>>>         return HttpResponse('Hello, World!')
>>>
>>>
>>> def put(self, request, *args, **kwargs):
>>>
>>>         return HttpResponse('Hello, World!')
>>>
>>>
>>> def delete(self, request, *args, **kwargs):
>>>
>>>         return HttpResponse('Hello, World!')
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Django users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to django-users+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/django-users/2cbd1753-d7d3-40d2-9d47-e935d0e3d75f%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-users/2cbd1753-d7d3-40d2-9d47-e935d0e3d75f%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django users" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to django-users+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-users/CACNsr2-Y7bPvDmCYRdLiZf5vVDbs6tX4EABF5HGzDUt3wvOjLA%40mail.gmail.com
>> <https://groups.google.com/d/msgid/django-users/CACNsr2-Y7bPvDmCYRdLiZf5vVDbs6tX4EABF5HGzDUt3wvOjLA%40mail.gmail.com?utm_medium=email&utm_source=footer>
>> .
>>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CA%2BEpJfxOrX0thTdb%3DoikwmTyGYCGVo4zdbGyA6UxvvyV3E7TLg%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CA%2BEpJfxOrX0thTdb%3DoikwmTyGYCGVo4zdbGyA6UxvvyV3E7TLg%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CACNsr28poENPaFMrs1HhBNHneNqd1XAi4AdoYa5jsbqZUiDo%3DA%40mail.gmail.com.

Reply via email to