diff options
Diffstat (limited to 'tutorial/6-viewsets-and-routers.html')
| -rw-r--r-- | tutorial/6-viewsets-and-routers.html | 12 | 
1 files changed, 6 insertions, 6 deletions
| diff --git a/tutorial/6-viewsets-and-routers.html b/tutorial/6-viewsets-and-routers.html index f8d2f5eb..da4c6383 100644 --- a/tutorial/6-viewsets-and-routers.html +++ b/tutorial/6-viewsets-and-routers.html @@ -275,19 +275,19 @@ user_detail = UserViewSet.as_view({  </code></pre>  <p>Notice how we're creating multiple views from each <code>ViewSet</code> class, by binding the http methods to the required action for each view.</p>  <p>Now that we've bound our resources into concrete views, we can register the views with the URL conf as usual.</p> -<pre class="prettyprint lang-py"><code>urlpatterns = format_suffix_patterns(patterns('snippets.views', -    url(r'^$', 'api_root'), +<pre class="prettyprint lang-py"><code>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') -)) +])  </code></pre>  <h2 id="using-routers">Using Routers</h2>  <p>Because we're using <code>ViewSet</code> classes rather than <code>View</code> classes, we actually don't need to design the URL conf ourselves.  The conventions for wiring up resources into views and urls can be handled automatically, using a <code>Router</code> class.  All we need to do is register the appropriate view sets with a router, and let it do the rest.</p>  <p>Here's our re-wired <code>urls.py</code> file.</p> -<pre class="prettyprint lang-py"><code>from django.conf.urls import patterns, url, include +<pre class="prettyprint lang-py"><code>from django.conf.urls import url, include  from snippets import views  from rest_framework.routers import DefaultRouter @@ -298,10 +298,10 @@ router.register(r'users', views.UserViewSet)  # 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')) -) +]  </code></pre>  <p>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.</p>  <p>The <code>DefaultRouter</code> class we're using also automatically creates the API root view for us, so we can now delete the <code>api_root</code> method from our <code>views</code> module.</p> | 
