From f723091ee907b5783723348b64c37d5d93751f18 Mon Sep 17 00:00:00 2001 From: Esmail Date: Wed, 11 Mar 2015 11:01:10 -0400 Subject: [PATCH] Fix example of explicit format URL. The link is displayed in the tutorial as "http://example.com/api/items/4.json" but the hyperlink itself and what the example code actually works with are (in my opinion, less pretty) URLs like "http://example.com/api/items/4/.json". --- tutorial/2-requests-and-responses/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tutorial/2-requests-and-responses/index.html b/tutorial/2-requests-and-responses/index.html index df43617a2..7357244b8 100644 --- a/tutorial/2-requests-and-responses/index.html +++ b/tutorial/2-requests-and-responses/index.html @@ -473,7 +473,7 @@ def snippet_detail(request, pk):

This should all feel very familiar - it is not a lot different from working with regular Django views.

Notice that we're no longer explicitly tying our requests or responses to a given content type. request.data can handle incoming json requests, but it can also handle other formats. Similarly we're returning response objects with data, but allowing REST framework to render the response into the correct content type for us.

Adding optional format suffixes to our URLs

-

To take advantage of the fact that our responses are no longer hardwired to a single content type let's add support for format suffixes to our API endpoints. Using format suffixes gives us URLs that explicitly refer to a given format, and means our API will be able to handle URLs such as http://example.com/api/items/4/.json.

+

To take advantage of the fact that our responses are no longer hardwired to a single content type let's add support for format suffixes to our API endpoints. Using format suffixes gives us URLs that explicitly refer to a given format, and means our API will be able to handle URLs such as http://example.com/api/items/4/.json.

Start by adding a format keyword argument to both of the views, like so.

def snippet_list(request, format=None):
 
@@ -608,4 +608,4 @@ http --json POST http://127.0.0.1:8000/snippets/ code="print 456" - \ No newline at end of file +