@@ -150,7 +150,7 @@ At this point we've translated the model instance into Python native datatypes.
150150
151151 content = JSONRenderer().render(serializer.data)
152152 content
153- # b'{"id": 2, "title": "", "code": "print(\\"hello, world\\")\\n", "linenos": false, "language": "python", "style": "friendly"}'
153+ # b'{"id":2, "title":"","code":"print(\\"hello, world\\")\\n","linenos":false,"language":"python","style":"friendly"}'
154154
155155Deserialization is similar. First we parse a stream into Python native datatypes...
156156
@@ -165,7 +165,7 @@ Deserialization is similar. First we parse a stream into Python native datatype
165165 serializer.is_valid()
166166 # True
167167 serializer.validated_data
168- # OrderedDict([( 'title', ''), ( 'code', 'print("hello, world")\n'), ( 'linenos', False), ( 'language', 'python'), ( 'style', 'friendly')])
168+ # { 'title': '', 'code': 'print("hello, world")', 'linenos': False, 'language': 'python', 'style': 'friendly'}
169169 serializer.save()
170170 # <Snippet: Snippet object>
171171
@@ -175,7 +175,7 @@ We can also serialize querysets instead of model instances. To do so we simply
175175
176176 serializer = SnippetSerializer(Snippet.objects.all(), many=True)
177177 serializer.data
178- # [OrderedDict([( 'id', 1), ( 'title', ''), ( 'code', 'foo = "bar"\n'), ( 'linenos', False), ( 'language', 'python'), ( 'style', 'friendly')]), OrderedDict([( 'id', 2), ( 'title', ''), ( 'code', 'print("hello, world")\n'), ( 'linenos', False), ( 'language', 'python'), ( 'style', 'friendly')]), OrderedDict([( 'id', 3), ( 'title', ''), ( 'code', 'print("hello, world")'), ( 'linenos', False), ( 'language', 'python'), ( 'style', 'friendly')]) ]
178+ # [{ 'id': 1, 'title': '', 'code': 'foo = "bar"\n', 'linenos': False, 'language': 'python', 'style': 'friendly'}, { 'id': 2, 'title': '', 'code': 'print("hello, world")\n', 'linenos': False, 'language': 'python', 'style': 'friendly'}, { 'id': 3, 'title': '', 'code': 'print("hello, world")', 'linenos': False, 'language': 'python', 'style': 'friendly'} ]
179179
180180## Using ModelSerializers
181181
@@ -321,42 +321,50 @@ You can install httpie using pip:
321321
322322Finally, we can get a list of all of the snippets:
323323
324- http http://127.0.0.1:8000/snippets/
324+ http http://127.0.0.1:8000/snippets/ --unsorted
325325
326326 HTTP/1.1 200 OK
327327 ...
328328 [
329- {
330- "id": 1,
331- "title": "",
332- "code": "foo = \"bar\"\n",
333- "linenos": false,
334- "language": "python",
335- "style": "friendly"
336- },
337- {
338- "id": 2,
339- "title": "",
340- "code": "print(\"hello, world\")\n",
341- "linenos": false,
342- "language": "python",
343- "style": "friendly"
344- }
329+ {
330+ "id": 1,
331+ "title": "",
332+ "code": "foo = \"bar\"\n",
333+ "linenos": false,
334+ "language": "python",
335+ "style": "friendly"
336+ },
337+ {
338+ "id": 2,
339+ "title": "",
340+ "code": "print(\"hello, world\")\n",
341+ "linenos": false,
342+ "language": "python",
343+ "style": "friendly"
344+ },
345+ {
346+ "id": 3,
347+ "title": "",
348+ "code": "print(\"hello, world\")",
349+ "linenos": false,
350+ "language": "python",
351+ "style": "friendly"
352+ }
345353 ]
346354
347355Or we can get a particular snippet by referencing its id:
348356
349- http http://127.0.0.1:8000/snippets/2/
357+ http http://127.0.0.1:8000/snippets/2/ --unsorted
350358
351359 HTTP/1.1 200 OK
352360 ...
353361 {
354- "id": 2,
355- "title": "",
356- "code": "print(\"hello, world\")\n",
357- "linenos": false,
358- "language": "python",
359- "style": "friendly"
362+ "id": 2,
363+ "title": "",
364+ "code": "print(\"hello, world\")\n",
365+ "linenos": false,
366+ "language": "python",
367+ "style": "friendly"
360368 }
361369
362370Similarly, you can have the same json displayed by visiting these URLs in a web browser.
0 commit comments