From 684a988fd9b473deec226297a79fba844a6f9d4d Mon Sep 17 00:00:00 2001 From: atkawa7 Date: Thu, 2 Mar 2017 20:25:35 -0700 Subject: [PATCH] directly using Django's JSONResponse --- docs/tutorial/1-serialization.md | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 710dfb8e7..4d2657346 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -216,26 +216,15 @@ It's important to remember that `ModelSerializer` classes don't do anything part Let's see how we can write some API views using our new Serializer class. For the moment we won't use any of REST framework's other features, we'll just write the views as regular Django views. -We'll start off by creating a subclass of HttpResponse that we can use to render any data we return into `json`. - Edit the `snippets/views.py` file, and add the following. - from django.http import HttpResponse + from django.http import HttpResponse, JSONResponse from django.views.decorators.csrf import csrf_exempt from rest_framework.renderers import JSONRenderer from rest_framework.parsers import JSONParser from snippets.models import Snippet from snippets.serializers import SnippetSerializer - class JSONResponse(HttpResponse): - """ - An HttpResponse that renders its content into JSON. - """ - def __init__(self, data, **kwargs): - content = JSONRenderer().render(data) - kwargs['content_type'] = 'application/json' - super(JSONResponse, self).__init__(content, **kwargs) - The root of our API is going to be a view that supports listing all the existing snippets, or creating a new snippet. @csrf_exempt