From 66cc2d3d5d611c57638a59932cd65c62d9b130c2 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 23 Dec 2013 12:37:56 +0000 Subject: Switch title ordering. --- tutorial/2-requests-and-responses.html | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'tutorial/2-requests-and-responses.html') diff --git a/tutorial/2-requests-and-responses.html b/tutorial/2-requests-and-responses.html index 6b5f67da..ef821cec 100644 --- a/tutorial/2-requests-and-responses.html +++ b/tutorial/2-requests-and-responses.html @@ -2,7 +2,7 @@ - Django REST framework - Tutorial 2: Requests and Responses + Tutorial 2: Requests and Responses - Django REST framework @@ -255,8 +255,7 @@ def snippet_list(request): if serializer.is_valid(): serializer.save() return Response(serializer.data, status=status.HTTP_201_CREATED) - else: - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

Our instance view is an improvement over the previous example. It's a little more concise, and the code now feels very similar to if we were working with the Forms API. We're also using named status codes, which makes the response meanings more obvious.

Here is the view for an individual snippet, in the views.py module.

@@ -279,8 +278,7 @@ def snippet_detail(request, pk): if serializer.is_valid(): serializer.save() return Response(serializer.data) - else: - return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) + return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) elif request.method == 'DELETE': snippet.delete() -- cgit v1.2.3