mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-27 03:54:01 +03:00
Merge pull request #573 from Wackerbarth/tutorial
Make the whitespace uniform
This commit is contained in:
commit
6e1fe0a818
|
@ -202,8 +202,6 @@ Open the file `snippets/serializers.py` again, and edit the `SnippetSerializer`
|
|||
model = Snippet
|
||||
fields = ('id', 'title', 'code', 'linenos', 'language', 'style')
|
||||
|
||||
|
||||
|
||||
## Writing regular Django views using our Serializer
|
||||
|
||||
Let's see how we can write some API views using our new Serializer class.
|
||||
|
@ -229,7 +227,6 @@ Edit the `snippet/views.py` file, and add the following.
|
|||
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
|
||||
|
|
|
@ -31,7 +31,6 @@ These wrappers provide a few bits of functionality such as making sure you recei
|
|||
|
||||
The wrappers also provide behaviour such as returning `405 Method Not Allowed` responses when appropriate, and handling any `ParseError` exception that occurs when accessing `request.DATA` with malformed input.
|
||||
|
||||
|
||||
## Pulling it all together
|
||||
|
||||
Okay, let's go ahead and start using these new components to write a few views.
|
||||
|
@ -63,7 +62,6 @@ We don't need our `JSONResponse` class anymore, so go ahead and delete that. On
|
|||
else:
|
||||
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.
|
||||
|
@ -138,7 +136,6 @@ Because the API chooses a return format based on what the client asks for, it wi
|
|||
|
||||
See the [browsable api][browseable-api] topic for more information about the browsable API feature and how to customize it.
|
||||
|
||||
|
||||
## What's next?
|
||||
|
||||
In [tutorial part 3][tut-3], we'll start using class based views, and see how generic views reduce the amount of code we need to write.
|
||||
|
|
Loading…
Reference in New Issue
Block a user