diff options
Diffstat (limited to 'docs/tutorial')
| -rw-r--r-- | docs/tutorial/1-serialization.md | 13 | ||||
| -rw-r--r-- | docs/tutorial/2-requests-and-responses.md | 9 | ||||
| -rw-r--r-- | docs/tutorial/3-class-based-views.md | 4 | ||||
| -rw-r--r-- | docs/tutorial/4-authentication-and-permissions.md | 4 | ||||
| -rw-r--r-- | docs/tutorial/5-relationships-and-hyperlinked-apis.md | 10 | ||||
| -rw-r--r-- | docs/tutorial/6-viewsets-and-routers.md | 12 | 
6 files changed, 27 insertions, 25 deletions
| diff --git a/docs/tutorial/1-serialization.md b/docs/tutorial/1-serialization.md index 96214f5b..b0565d91 100644 --- a/docs/tutorial/1-serialization.md +++ b/docs/tutorial/1-serialization.md @@ -64,9 +64,9 @@ We'll also need to add our new `snippets` app and the `rest_framework` app to `I  We also need to wire up the root urlconf, in the `tutorial/urls.py` file, to include our snippet app's URLs. -    urlpatterns = patterns('', +    urlpatterns = [          url(r'^', include('snippets.urls')), -    ) +    ]  Okay, we're ready to roll. @@ -297,11 +297,12 @@ We'll also need a view which corresponds to an individual snippet, and can be us  Finally we need to wire these views up.  Create the `snippets/urls.py` file:      from django.conf.urls import patterns, url +    from snippets import views -    urlpatterns = patterns('snippets.views', -        url(r'^snippets/$', 'snippet_list'), -        url(r'^snippets/(?P<pk>[0-9]+)/$', 'snippet_detail'), -    ) +    urlpatterns = [ +        url(r'^snippets/$', views.snippet_list), +        url(r'^snippets/(?P<pk>[0-9]+)/$', views.snippet_detail), +    ]  It's worth noting that there are a couple of edge cases we're not dealing with properly at the moment.  If we send malformed `json`, or if a request is made with a method that the view doesn't handle, then we'll end up with a 500 "server error" response.  Still, this'll do for now. diff --git a/docs/tutorial/2-requests-and-responses.md b/docs/tutorial/2-requests-and-responses.md index e70bbbfc..136b0135 100644 --- a/docs/tutorial/2-requests-and-responses.md +++ b/docs/tutorial/2-requests-and-responses.md @@ -110,11 +110,12 @@ Now update the `urls.py` file slightly, to append a set of `format_suffix_patter      from django.conf.urls import patterns, url      from rest_framework.urlpatterns import format_suffix_patterns +    from snippets import views -    urlpatterns = patterns('snippets.views', -        url(r'^snippets/$', 'snippet_list'), -        url(r'^snippets/(?P<pk>[0-9]+)$', 'snippet_detail'), -    ) +    urlpatterns = [ +        url(r'^snippets/$', views.snippet_list), +        url(r'^snippets/(?P<pk>[0-9]+)$', views.snippet_detail), +    ]      urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/docs/tutorial/3-class-based-views.md b/docs/tutorial/3-class-based-views.md index e04072ca..382f078a 100644 --- a/docs/tutorial/3-class-based-views.md +++ b/docs/tutorial/3-class-based-views.md @@ -68,10 +68,10 @@ We'll also need to refactor our `urls.py` slightly now we're using class based v      from rest_framework.urlpatterns import format_suffix_patterns      from snippets import views -    urlpatterns = patterns('', +    urlpatterns = [          url(r'^snippets/$', views.SnippetList.as_view()),          url(r'^snippets/(?P<pk>[0-9]+)/$', views.SnippetDetail.as_view()), -    ) +    ]      urlpatterns = format_suffix_patterns(urlpatterns) diff --git a/docs/tutorial/4-authentication-and-permissions.md b/docs/tutorial/4-authentication-and-permissions.md index 74ad9a55..9120e254 100644 --- a/docs/tutorial/4-authentication-and-permissions.md +++ b/docs/tutorial/4-authentication-and-permissions.md @@ -137,10 +137,10 @@ Add the following import at the top of the file:  And, at the end of the file, add a pattern to include the login and logout views for the browsable API. -    urlpatterns += patterns('', +    urlpatterns += [          url(r'^api-auth/', include('rest_framework.urls',                                     namespace='rest_framework')), -    ) +    ]  The `r'^api-auth/'` part of pattern can actually be whatever URL you want to use.  The only restriction is that the included urls must use the `'rest_framework'` namespace. diff --git a/docs/tutorial/5-relationships-and-hyperlinked-apis.md b/docs/tutorial/5-relationships-and-hyperlinked-apis.md index 9c61fe3d..36473ce9 100644 --- a/docs/tutorial/5-relationships-and-hyperlinked-apis.md +++ b/docs/tutorial/5-relationships-and-hyperlinked-apis.md @@ -108,8 +108,8 @@ If we're going to have a hyperlinked API, we need to make sure we name our URL p  After adding all those names into our URLconf, our final `snippets/urls.py` file should look something like this:      # API endpoints -    urlpatterns = format_suffix_patterns(patterns('snippets.views', -        url(r'^$', 'api_root'), +    urlpatterns = format_suffix_patterns([ +        url(r'^$', views.api_root),          url(r'^snippets/$',              views.SnippetList.as_view(),              name='snippet-list'), @@ -125,13 +125,13 @@ After adding all those names into our URLconf, our final `snippets/urls.py` file          url(r'^users/(?P<pk>[0-9]+)/$',              views.UserDetail.as_view(),              name='user-detail') -    )) +    ])      # Login and logout views for the browsable API -    urlpatterns += patterns('', +    urlpatterns += [          url(r'^api-auth/', include('rest_framework.urls',                                     namespace='rest_framework')), -    ) +    ]  ## Adding pagination diff --git a/docs/tutorial/6-viewsets-and-routers.md b/docs/tutorial/6-viewsets-and-routers.md index b2019520..cf37a260 100644 --- a/docs/tutorial/6-viewsets-and-routers.md +++ b/docs/tutorial/6-viewsets-and-routers.md @@ -87,14 +87,14 @@ Notice how we're creating multiple views from each `ViewSet` class, by binding t  Now that we've bound our resources into concrete views, we can register the views with the URL conf as usual. -    urlpatterns = format_suffix_patterns(patterns('snippets.views', -        url(r'^$', 'api_root'), +    urlpatterns = format_suffix_patterns([ +        url(r'^$', api_root),          url(r'^snippets/$', snippet_list, name='snippet-list'),          url(r'^snippets/(?P<pk>[0-9]+)/$', snippet_detail, name='snippet-detail'),          url(r'^snippets/(?P<pk>[0-9]+)/highlight/$', snippet_highlight, name='snippet-highlight'),          url(r'^users/$', user_list, name='user-list'),          url(r'^users/(?P<pk>[0-9]+)/$', user_detail, name='user-detail') -    )) +    ])  ## Using Routers @@ -102,7 +102,7 @@ Because we're using `ViewSet` classes rather than `View` classes, we actually do  Here's our re-wired `urls.py` file. -    from django.conf.urls import patterns, url, include +    from django.conf.urls import url, include      from snippets import views      from rest_framework.routers import DefaultRouter @@ -113,10 +113,10 @@ Here's our re-wired `urls.py` file.      # The API URLs are now determined automatically by the router.      # Additionally, we include the login URLs for the browseable API. -    urlpatterns = patterns('', +    urlpatterns = [          url(r'^', include(router.urls)),          url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')) -    ) +    ]  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. | 
