aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Christie2014-09-24 09:02:53 +0100
committerTom Christie2014-09-24 09:02:53 +0100
commit4ffae7c0e959e42fa2dde830ac144e94ee8aae71 (patch)
treeeb878800eb479fdf072b8315282ec2b1fdea8ba2
parent8495cd898a5d34f00858a379b54e39cd19ded215 (diff)
parentda385c9c1f9deeeefd705154a6e6612d6d62f41b (diff)
downloaddjango-rest-framework-4ffae7c0e959e42fa2dde830ac144e94ee8aae71.tar.bz2
Merge pull request #1899 from collinanderson/urls
Remove patterns and strings from urls in tutorial.
-rwxr-xr-xdocs/api-guide/authentication.md7
-rw-r--r--docs/api-guide/format-suffixes.md13
-rw-r--r--docs/index.md4
-rw-r--r--docs/topics/2.3-announcement.md6
-rw-r--r--docs/tutorial/1-serialization.md13
-rw-r--r--docs/tutorial/2-requests-and-responses.md9
-rw-r--r--docs/tutorial/3-class-based-views.md4
-rw-r--r--docs/tutorial/4-authentication-and-permissions.md4
-rw-r--r--docs/tutorial/5-relationships-and-hyperlinked-apis.md10
-rw-r--r--docs/tutorial/6-viewsets-and-routers.md12
10 files changed, 43 insertions, 39 deletions
diff --git a/docs/api-guide/authentication.md b/docs/api-guide/authentication.md
index 343466ee..0ec5bad1 100755
--- a/docs/api-guide/authentication.md
+++ b/docs/api-guide/authentication.md
@@ -190,9 +190,10 @@ If you've already created some users, you can generate tokens for all existing u
When using `TokenAuthentication`, you may want to provide a mechanism for clients to obtain a token given the username and password. REST framework provides a built-in view to provide this behavior. To use it, add the `obtain_auth_token` view to your URLconf:
- urlpatterns += patterns('',
- url(r'^api-token-auth/', 'rest_framework.authtoken.views.obtain_auth_token')
- )
+ from rest_framework.authtoken import views
+ urlpatterns += [
+ url(r'^api-token-auth/', views.obtain_auth_token)
+ ]
Note that the URL part of the pattern can be whatever you want to use.
diff --git a/docs/api-guide/format-suffixes.md b/docs/api-guide/format-suffixes.md
index 529738e3..76a3367b 100644
--- a/docs/api-guide/format-suffixes.md
+++ b/docs/api-guide/format-suffixes.md
@@ -26,12 +26,13 @@ Arguments:
Example:
from rest_framework.urlpatterns import format_suffix_patterns
-
- urlpatterns = patterns('blog.views',
- url(r'^/$', 'api_root'),
- url(r'^comments/$', 'comment_list'),
- url(r'^comments/(?P<pk>[0-9]+)/$', 'comment_detail')
- )
+ from blog import views
+
+ urlpatterns = [
+ url(r'^/$', views.apt_root),
+ url(r'^comments/$', views.comment_list),
+ url(r'^comments/(?P<pk>[0-9]+)/$', views.comment_detail)
+ ]
urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'html'])
diff --git a/docs/index.md b/docs/index.md
index 6dcb962f..e4c971f9 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -85,10 +85,10 @@ Add `'rest_framework'` to your `INSTALLED_APPS` setting.
If you're intending to use the browsable API you'll probably also want to add REST framework's login and logout views. Add the following to your root `urls.py` file.
- urlpatterns = patterns('',
+ urlpatterns = [
...
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
- )
+ ]
Note that the URL path can be whatever you want, but you must include `'rest_framework.urls'` with the `'rest_framework'` namespace.
diff --git a/docs/topics/2.3-announcement.md b/docs/topics/2.3-announcement.md
index ba435145..7c800afa 100644
--- a/docs/topics/2.3-announcement.md
+++ b/docs/topics/2.3-announcement.md
@@ -15,7 +15,7 @@ As an example of just how simple REST framework APIs can now be, here's an API w
"""
A REST framework API for viewing and editing users and groups.
"""
- from django.conf.urls.defaults import url, patterns, include
+ from django.conf.urls.defaults import url, include
from django.contrib.auth.models import User, Group
from rest_framework import viewsets, routers
@@ -36,10 +36,10 @@ As an example of just how simple REST framework APIs can now be, here's an API w
# Wire up our API using automatic URL routing.
# Additionally, we include 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'))
- )
+ ]
The best place to get started with ViewSets and Routers is to take a look at the [newest section in the tutorial][part-6], which demonstrates their usage.
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.