mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-04 23:44:07 +03:00
Use named links in tutorial docs
This commit is contained in:
parent
efba6a7285
commit
8d14f74964
|
@ -217,7 +217,7 @@ urlpatterns = format_suffix_patterns(urlpatterns)
|
||||||
<p>Because the API chooses a return format based on what the client asks for, it will, by default, return an HTML-formatted representation of the resource when that resource is requested by a browser. This allows for the API to be easily browsable and usable by humans.</p>
|
<p>Because the API chooses a return format based on what the client asks for, it will, by default, return an HTML-formatted representation of the resource when that resource is requested by a browser. This allows for the API to be easily browsable and usable by humans.</p>
|
||||||
<p>See the <a href="../topics/browsable-api">browsable api</a> topic for more information about the browsable API feature and how to customize it.</p>
|
<p>See the <a href="../topics/browsable-api">browsable api</a> topic for more information about the browsable API feature and how to customize it.</p>
|
||||||
<h2 id="whats-next">What's next?</h2>
|
<h2 id="whats-next">What's next?</h2>
|
||||||
<p>In <a href="../topics/browsable-api">tutorial part 3</a>, we'll start using class based views, and see how generic views reduce the amount of code we need to write.</p>
|
<p>In <a href="3-class-based-views">tutorial part 3</a>, we'll start using class based views, and see how generic views reduce the amount of code we need to write.</p>
|
||||||
</div><!--/span-->
|
</div><!--/span-->
|
||||||
</div><!--/row-->
|
</div><!--/row-->
|
||||||
</div><!--/.fluid-container-->
|
</div><!--/.fluid-container-->
|
||||||
|
|
|
@ -93,13 +93,15 @@
|
||||||
<div class="span3">
|
<div class="span3">
|
||||||
<div id="table-of-contents" class="well affix span3">
|
<div id="table-of-contents" class="well affix span3">
|
||||||
<ul class="nav nav-list side-nav">
|
<ul class="nav nav-list side-nav">
|
||||||
|
<li class="main"><a href="#tutorial-4-authentication-&-permissions">Tutorial 4: Authentication & Permissions</a></li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="main-content" class="span9">
|
<div id="main-content" class="span9">
|
||||||
<p><a href="5-relationships-and-hyperlinked-apis">part 5</a></p>
|
<h1 id="tutorial-4-authentication-permissions">Tutorial 4: Authentication & Permissions</h1>
|
||||||
|
<p>Nothing to see here. Onwards to <a href="5-relationships-and-hyperlinked-apis">part 5</a>.</p>
|
||||||
</div><!--/span-->
|
</div><!--/span-->
|
||||||
</div><!--/row-->
|
</div><!--/row-->
|
||||||
</div><!--/.fluid-container-->
|
</div><!--/.fluid-container-->
|
||||||
|
|
|
@ -93,19 +93,21 @@
|
||||||
<div class="span3">
|
<div class="span3">
|
||||||
<div id="table-of-contents" class="well affix span3">
|
<div id="table-of-contents" class="well affix span3">
|
||||||
<ul class="nav nav-list side-nav">
|
<ul class="nav nav-list side-nav">
|
||||||
|
<li class="main"><a href="#tutorial-5---relationships-&-hyperlinked-apis">Tutorial 5 - Relationships & Hyperlinked APIs</a></li>
|
||||||
|
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="main-content" class="span9">
|
<div id="main-content" class="span9">
|
||||||
<p><strong>TODO</strong></p>
|
<h1 id="tutorial-5-relationships-hyperlinked-apis">Tutorial 5 - Relationships & Hyperlinked APIs</h1>
|
||||||
|
<p><strong>TODO</strong></p>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Create BlogPost model</li>
|
<li>Create BlogPost model</li>
|
||||||
<li>Demonstrate nested relationships</li>
|
<li>Demonstrate nested relationships</li>
|
||||||
<li>Demonstrate and describe hyperlinked relationships</li>
|
<li>Demonstrate and describe hyperlinked relationships</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p><a href="6-resource-orientated-projects">part 6</a></p>
|
<p>Onwards to <a href="6-resource-orientated-projects">part 6</a>.</p>
|
||||||
</div><!--/span-->
|
</div><!--/span-->
|
||||||
</div><!--/row-->
|
</div><!--/row-->
|
||||||
</div><!--/.fluid-container-->
|
</div><!--/.fluid-container-->
|
||||||
|
|
|
@ -93,7 +93,10 @@
|
||||||
<div class="span3">
|
<div class="span3">
|
||||||
<div id="table-of-contents" class="well affix span3">
|
<div id="table-of-contents" class="well affix span3">
|
||||||
<ul class="nav nav-list side-nav">
|
<ul class="nav nav-list side-nav">
|
||||||
<li><a href="#using-routers">Using Routers</a></li>
|
<li class="main"><a href="#tutorial-6---resources">Tutorial 6 - Resources</a></li>
|
||||||
|
<li><a href="#refactoring-to-use-resources,-not-views">Refactoring to use Resources, not Views</a></li>
|
||||||
|
<li><a href="#binding-resources-to-urls-explicitly">Binding Resources to URLs explicitly</a></li>
|
||||||
|
<li><a href="#using-routers">Using Routers</a></li>
|
||||||
<li><a href="#trade-offs-between-views-vs-resources">Trade-offs between views vs resources.</a></li>
|
<li><a href="#trade-offs-between-views-vs-resources">Trade-offs between views vs resources.</a></li>
|
||||||
<li><a href="#onwards-and-upwards">Onwards and upwards.</a></li>
|
<li><a href="#onwards-and-upwards">Onwards and upwards.</a></li>
|
||||||
|
|
||||||
|
@ -102,18 +105,15 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="main-content" class="span9">
|
<div id="main-content" class="span9">
|
||||||
<p>In REST framework Resources classes are just View classes that don't have any handler methods bound to them. This allows us to seperate out the behaviour of the classes from how that behaviour should be bound to a set of URLs.</p>
|
<h1 id="tutorial-6-resources">Tutorial 6 - Resources</h1>
|
||||||
<p>For instance, given our serializers</p>
|
<p>Resource classes are just View classes that don't have any handler methods bound to them. The actions on a resource are defined, </p>
|
||||||
<p>serializers.py</p>
|
<p>This allows us to:</p>
|
||||||
<pre class="prettyprint lang-py"><code>class BlogPostSerializer(URLModelSerializer):
|
<ul>
|
||||||
class Meta:
|
<li>Encapsulate common behaviour accross a class of views, in a single Resource class.</li>
|
||||||
model = BlogPost
|
<li>Seperate out the actions of a Resource from the specfics of how those actions should be bound to a particular set of URLs.</li>
|
||||||
|
</ul>
|
||||||
class CommentSerializer(URLModelSerializer):
|
<h2 id="refactoring-to-use-resources-not-views">Refactoring to use Resources, not Views</h2>
|
||||||
class Meta:
|
<p>For instance, we can re-write our 4 sets of views into something more compact...</p>
|
||||||
model = Comment
|
|
||||||
</code></pre>
|
|
||||||
<p>We can re-write our 4 sets of views into something more compact...</p>
|
|
||||||
<p>resources.py</p>
|
<p>resources.py</p>
|
||||||
<pre class="prettyprint lang-py"><code>class BlogPostResource(ModelResource):
|
<pre class="prettyprint lang-py"><code>class BlogPostResource(ModelResource):
|
||||||
serializer_class = BlogPostSerializer
|
serializer_class = BlogPostSerializer
|
||||||
|
@ -127,6 +127,7 @@ class CommentResource(ModelResource):
|
||||||
permissions_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
permissions_classes = (permissions.IsAuthenticatedOrReadOnly,)
|
||||||
throttle_classes = (throttles.UserRateThrottle,)
|
throttle_classes = (throttles.UserRateThrottle,)
|
||||||
</code></pre>
|
</code></pre>
|
||||||
|
<h2 id="binding-resources-to-urls-explicitly">Binding Resources to URLs explicitly</h2>
|
||||||
<p>The handler methods only get bound to the actions when we define the URLConf. Here's our urls.py:</p>
|
<p>The handler methods only get bound to the actions when we define the URLConf. Here's our urls.py:</p>
|
||||||
<pre class="prettyprint lang-py"><code>comment_root = CommentResource.as_view(actions={
|
<pre class="prettyprint lang-py"><code>comment_root = CommentResource.as_view(actions={
|
||||||
'get': 'list',
|
'get': 'list',
|
||||||
|
@ -165,7 +166,7 @@ urlpatterns = router.urlpatterns
|
||||||
<li>Join the REST framework group, and help build the community.</li>
|
<li>Join the REST framework group, and help build the community.</li>
|
||||||
<li>Follow me <a href="https://twitter.com/_tomchristie">on Twitter</a> and say hi.</li>
|
<li>Follow me <a href="https://twitter.com/_tomchristie">on Twitter</a> and say hi.</li>
|
||||||
</ul>
|
</ul>
|
||||||
<p>Now go build something great.</p>
|
<p><strong>Now go build some awesome things.</strong></p>
|
||||||
</div><!--/span-->
|
</div><!--/span-->
|
||||||
</div><!--/row-->
|
</div><!--/row-->
|
||||||
</div><!--/.fluid-container-->
|
</div><!--/.fluid-container-->
|
||||||
|
|
Loading…
Reference in New Issue
Block a user