From cce3134e19ca8b8ce97c331b73e3ae115d905dcb Mon Sep 17 00:00:00 2001 From: Chris Shyi Date: Thu, 21 Jun 2018 16:54:46 -0400 Subject: [PATCH 1/3] Update to Django 2.0 Routing Syntax Updated the code in tutorial part 6, "Using Routers", to Django 2.0 routing syntax using path(). --- docs/tutorial/6-viewsets-and-routers.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md index ff458e2067..f23a435b8a 100644 --- a/docs/tutorial/6-viewsets-and-routers.md +++ b/docs/tutorial/6-viewsets-and-routers.md @@ -3,7 +3,6 @@ REST framework includes an abstraction for dealing with `ViewSets`, that allows the developer to concentrate on modeling the state and interactions of the API, and leave the URL construction to be handled automatically, based on common conventions. `ViewSet` classes are almost the same thing as `View` classes, except that they provide operations such as `read`, or `update`, and not method handlers such as `get` or `put`. - A `ViewSet` class is only bound to a set of method handlers at the last moment, when it is instantiated into a set of views, typically by using a `Router` class which handles the complexities of defining the URL conf for you. ## Refactoring to use ViewSets @@ -116,7 +115,7 @@ Here's our re-wired `snippets/urls.py` file. # The API URLs are now determined automatically by the router. urlpatterns = [ - url(r'^', include(router.urls)) + path('', include(router.urls)), ] Registering the viewsets with the router is similar to providing a urlpattern. We include two arguments - the URL prefix for the views, and the viewset itself. From 2786f1b023cf88bfd793585c5c6739f2d05bb513 Mon Sep 17 00:00:00 2001 From: Chris Shyi Date: Thu, 21 Jun 2018 18:52:37 -0400 Subject: [PATCH 2/3] Fixed a newline that was erased in the last commit --- docs/tutorial/6-viewsets-and-routers.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md index f23a435b8a..d5ec66004e 100644 --- a/docs/tutorial/6-viewsets-and-routers.md +++ b/docs/tutorial/6-viewsets-and-routers.md @@ -3,6 +3,7 @@ REST framework includes an abstraction for dealing with `ViewSets`, that allows the developer to concentrate on modeling the state and interactions of the API, and leave the URL construction to be handled automatically, based on common conventions. `ViewSet` classes are almost the same thing as `View` classes, except that they provide operations such as `read`, or `update`, and not method handlers such as `get` or `put`. + A `ViewSet` class is only bound to a set of method handlers at the last moment, when it is instantiated into a set of views, typically by using a `Router` class which handles the complexities of defining the URL conf for you. ## Refactoring to use ViewSets From 1d0338cff1e5e5ca6beb2e96c8f7d789ff83b921 Mon Sep 17 00:00:00 2001 From: Chris Shyi Date: Thu, 21 Jun 2018 19:09:09 -0400 Subject: [PATCH 3/3] Fix import in code example Fixed the import statement in tutorial part 6 for the path() and include() functions. --- docs/tutorial/6-viewsets-and-routers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md index d5ec66004e..1d40588135 100644 --- a/docs/tutorial/6-viewsets-and-routers.md +++ b/docs/tutorial/6-viewsets-and-routers.md @@ -105,7 +105,7 @@ Because we're using `ViewSet` classes rather than `View` classes, we actually do Here's our re-wired `snippets/urls.py` file. - from django.conf.urls import url, include + from django.urls import path, include from rest_framework.routers import DefaultRouter from snippets import views