mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-01-28 02:04:07 +03:00
Deployed cf3862d5
with MkDocs version: 0.15.3
This commit is contained in:
parent
a8ed1ee247
commit
f5c7d8f0f6
|
@ -389,6 +389,16 @@
|
|||
</li>
|
||||
|
||||
|
||||
<li class="main">
|
||||
<a href="#third-party-packages">Third party packages</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<a href="#drf-schema-adapter">DRF-schema-adapter</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<div class="promo">
|
||||
<hr/>
|
||||
|
@ -494,6 +504,12 @@ def schema(self, request):
|
|||
'DEFAULT_METADATA_CLASS': 'myproject.apps.core.MinimalMetadata'
|
||||
}
|
||||
</code></pre>
|
||||
<h1 id="third-party-packages"><a class="toclink" href="#third-party-packages">Third party packages</a></h1>
|
||||
<p>The following third party packages provide additional metadata implementations.</p>
|
||||
<h2 id="drf-schema-adapter"><a class="toclink" href="#drf-schema-adapter">DRF-schema-adapter</a></h2>
|
||||
<p><a href="https://github.com/drf-forms/drf-schema-adapter">drf-schema-adapter</a> is a set of tools that makes it easier to provide schema information to frontend frameworks and libraries. It provides a metadata mixin as well as 2 metadata classes and several adapters suitable to generate <a href="http://json-schema.org/">json-schema</a> as well as schema information readable by various libraries.</p>
|
||||
<p>You can also write your own adapter to work with your specific frontend.
|
||||
If you whish to do so, it also provides an exporter that can export those schema information to json files.</p>
|
||||
|
||||
|
||||
</div> <!--/span-->
|
||||
|
|
|
@ -691,8 +691,8 @@ populate descriptions in the schema document.</p>
|
|||
<p>A generic view with sections in the class docstring, using single-line style.</p>
|
||||
<pre><code>class UserList(generics.ListCreateAPIView):
|
||||
"""
|
||||
get: Create a new user.
|
||||
post: List all the users.
|
||||
get: List all the users.
|
||||
post: Create a new user.
|
||||
"""
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
|
|
|
@ -448,10 +448,6 @@
|
|||
<a href="#relational-fields">Relational fields</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#inheritance-of-the-meta-class">Inheritance of the 'Meta' class</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#customizing-field-mappings">Customizing field mappings</a>
|
||||
</li>
|
||||
|
@ -516,6 +512,10 @@
|
|||
<a href="#overriding-serialization-and-deserialization-behavior">Overriding serialization and deserialization behavior</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#serializer-inheritance">Serializer Inheritance</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#dynamically-modifying-fields">Dynamically modifying fields</a>
|
||||
</li>
|
||||
|
@ -558,10 +558,26 @@
|
|||
<a href="#dynamic-fields-mixin">Dynamic Fields Mixin</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#drf-flexfields">DRF FlexFields</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#serializer-extensions">Serializer Extensions</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#html-json-forms">HTML JSON Forms</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#drf-base64">DRF-Base64</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#queryfields">QueryFields</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<div class="promo">
|
||||
|
@ -1033,13 +1049,6 @@ AccountSerializer():
|
|||
<p>When serializing model instances, there are a number of different ways you might choose to represent relationships. The default representation for <code>ModelSerializer</code> is to use the primary keys of the related instances.</p>
|
||||
<p>Alternative representations include serializing using hyperlinks, serializing complete nested representations, or serializing with a custom representation.</p>
|
||||
<p>For full details see the <a href="../relations/">serializer relations</a> documentation.</p>
|
||||
<h2 id="inheritance-of-the-meta-class"><a class="toclink" href="#inheritance-of-the-meta-class">Inheritance of the 'Meta' class</a></h2>
|
||||
<p>The inner <code>Meta</code> class on serializers is not inherited from parent classes by default. This is the same behavior as with Django's <code>Model</code> and <code>ModelForm</code> classes. If you want the <code>Meta</code> class to inherit from a parent class you must do so explicitly. For example:</p>
|
||||
<pre><code>class AccountSerializer(MyBaseSerializer):
|
||||
class Meta(MyBaseSerializer.Meta):
|
||||
model = Account
|
||||
</code></pre>
|
||||
<p>Typically we would recommend <em>not</em> using inheritance on inner Meta classes, but instead declaring all options explicitly.</p>
|
||||
<h2 id="customizing-field-mappings"><a class="toclink" href="#customizing-field-mappings">Customizing field mappings</a></h2>
|
||||
<p>The ModelSerializer class also exposes an API that you can override in order to alter how serializer fields are automatically determined when instantiating the serializer.</p>
|
||||
<p>Normally if a <code>ModelSerializer</code> does not generate the fields you need by default then you should either add them to the class explicitly, or simply use a regular <code>Serializer</code> class instead. However in some cases you may want to create a new base class that defines how the serializer fields are created for any given model.</p>
|
||||
|
@ -1369,6 +1378,37 @@ def all_high_scores(request):
|
|||
<p>Takes the unvalidated incoming data as input and should return the validated data that will be made available as <code>serializer.validated_data</code>. The return value will also be passed to the <code>.create()</code> or <code>.update()</code> methods if <code>.save()</code> is called on the serializer class.</p>
|
||||
<p>If any of the validation fails, then the method should raise a <code>serializers.ValidationError(errors)</code>. Typically the <code>errors</code> argument here will be a dictionary mapping field names to error messages.</p>
|
||||
<p>The <code>data</code> argument passed to this method will normally be the value of <code>request.data</code>, so the datatype it provides will depend on the parser classes you have configured for your API.</p>
|
||||
<h2 id="serializer-inheritance"><a class="toclink" href="#serializer-inheritance">Serializer Inheritance</a></h2>
|
||||
<p>Similar to Django forms, you can extend and reuse serializers through inheritance. This allows you to declare a common set of fields or methods on a parent class that can then be used in a number of serializers. For example,</p>
|
||||
<pre><code>class MyBaseSerializer(Serializer):
|
||||
my_field = serializers.CharField()
|
||||
|
||||
def validate_my_field(self):
|
||||
...
|
||||
|
||||
class MySerializer(MyBaseSerializer):
|
||||
...
|
||||
</code></pre>
|
||||
<p>Like Django's <code>Model</code> and <code>ModelForm</code> classes, the inner <code>Meta</code> class on serializers does not implicitly inherit from it's parents' inner <code>Meta</code> classes. If you want the <code>Meta</code> class to inherit from a parent class you must do so explicitly. For example:</p>
|
||||
<pre><code>class AccountSerializer(MyBaseSerializer):
|
||||
class Meta(MyBaseSerializer.Meta):
|
||||
model = Account
|
||||
</code></pre>
|
||||
<p>Typically we would recommend <em>not</em> using inheritance on inner Meta classes, but instead declaring all options explicitly.</p>
|
||||
<p>Additionally, the following caveats apply to serializer inheritance:</p>
|
||||
<ul>
|
||||
<li>Normal Python name resolution rules apply. If you have multiple base classes that declare a <code>Meta</code> inner class, only the first one will be used. This means the child’s <code>Meta</code>, if it exists, otherwise the <code>Meta</code> of the first parent, etc.</li>
|
||||
<li>
|
||||
<p>It’s possible to declaratively remove a <code>Field</code> inherited from a parent class by setting the name to be <code>None</code> on the subclass.</p>
|
||||
<pre><code>class MyBaseSerializer(ModelSerializer):
|
||||
my_field = serializers.CharField()
|
||||
|
||||
class MySerializer(MyBaseSerializer):
|
||||
my_field = None
|
||||
</code></pre>
|
||||
<p>However, you can only use this technique to opt out from a field defined declaratively by a parent class; it won’t prevent the <code>ModelSerializer</code> from generating a default field. To opt-out from default fields, see <a href="#specifying-which-fields-to-include">Specifying which fields to include</a>.</p>
|
||||
</li>
|
||||
</ul>
|
||||
<h2 id="dynamically-modifying-fields"><a class="toclink" href="#dynamically-modifying-fields">Dynamically modifying fields</a></h2>
|
||||
<p>Once a serializer has been initialized, the dictionary of fields that are set on the serializer may be accessed using the <code>.fields</code> attribute. Accessing and modifying this attribute allows you to dynamically modify the serializer.</p>
|
||||
<p>Modifying the <code>fields</code> argument directly allows you to do interesting things such as changing the arguments on serializer fields at runtime, rather than at the point of declaring the serializer.</p>
|
||||
|
@ -1428,8 +1468,19 @@ def all_high_scores(request):
|
|||
<p>The <a href="https://github.com/AltSchool/dynamic-rest">dynamic-rest</a> package extends the ModelSerializer and ModelViewSet interfaces, adding API query parameters for filtering, sorting, and including / excluding all fields and relationships defined by your serializers.</p>
|
||||
<h2 id="dynamic-fields-mixin"><a class="toclink" href="#dynamic-fields-mixin">Dynamic Fields Mixin</a></h2>
|
||||
<p>The <a href="https://github.com/dbrgn/drf-dynamic-fields">drf-dynamic-fields</a> package provides a mixin to dynamically limit the fields per serializer to a subset specified by an URL parameter.</p>
|
||||
<h2 id="drf-flexfields"><a class="toclink" href="#drf-flexfields">DRF FlexFields</a></h2>
|
||||
<p>The <a href="https://github.com/rsinger86/drf-flex-fields">drf-flex-fields</a> package extends the ModelSerializer and ModelViewSet to provide commonly used functionality for dynamically setting fields and expanding primitive fields to nested models, both from URL parameters and your serializer class definitions.</p>
|
||||
<h2 id="serializer-extensions"><a class="toclink" href="#serializer-extensions">Serializer Extensions</a></h2>
|
||||
<p>The <a href="https://github.com/evenicoulddoit/django-rest-framework-serializer-extensions">django-rest-framework-serializer-extensions</a>
|
||||
package provides a collection of tools to DRY up your serializers, by allowing
|
||||
fields to be defined on a per-view/request basis. Fields can be whitelisted,
|
||||
blacklisted and child serializers can be optionally expanded.</p>
|
||||
<h2 id="html-json-forms"><a class="toclink" href="#html-json-forms">HTML JSON Forms</a></h2>
|
||||
<p>The <a href="https://github.com/wq/html-json-forms">html-json-forms</a> package provides an algorithm and serializer for processing <code><form></code> submissions per the (inactive) <a href="https://www.w3.org/TR/html-json-forms/">HTML JSON Form specification</a>. The serializer facilitates processing of arbitrarily nested JSON structures within HTML. For example, <code><input name="items[0][id]" value="5"></code> will be interpreted as <code>{"items": [{"id": "5"}]}</code>.</p>
|
||||
<h2 id="drf-base64"><a class="toclink" href="#drf-base64">DRF-Base64</a></h2>
|
||||
<p><a href="https://bitbucket.org/levit_scs/drf_base64">DRF-Base64</a> provides a set of field and model serializers that handles the upload of base64-encoded files.</p>
|
||||
<h2 id="queryfields"><a class="toclink" href="#queryfields">QueryFields</a></h2>
|
||||
<p><a href="http://djangorestframework-queryfields.readthedocs.io/">djangorestframework-queryfields</a> allows API clients to specify which fields will be sent in the response via inclusion or exclusion query paramaters. </p>
|
||||
|
||||
|
||||
</div> <!--/span-->
|
||||
|
|
|
@ -477,6 +477,7 @@ class ListUsers(APIView):
|
|||
<h3 id="get_throttlesself"><a class="toclink" href="#get_throttlesself">.get_throttles(self)</a></h3>
|
||||
<h3 id="get_permissionsself"><a class="toclink" href="#get_permissionsself">.get_permissions(self)</a></h3>
|
||||
<h3 id="get_content_negotiatorself"><a class="toclink" href="#get_content_negotiatorself">.get_content_negotiator(self)</a></h3>
|
||||
<h3 id="get_exception_handlerself"><a class="toclink" href="#get_exception_handlerself">.get_exception_handler(self)</a></h3>
|
||||
<h2 id="api-policy-implementation-methods"><a class="toclink" href="#api-policy-implementation-methods">API policy implementation methods</a></h2>
|
||||
<p>The following methods are called before dispatching to the handler method.</p>
|
||||
<h3 id="check_permissionsself-request"><a class="toclink" href="#check_permissionsself-request">.check_permissions(self, request)</a></h3>
|
||||
|
|
File diff suppressed because one or more lines are too long
114
sitemap.xml
114
sitemap.xml
|
@ -4,7 +4,7 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -13,49 +13,49 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/quickstart/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/1-serialization/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/2-requests-and-responses/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/3-class-based-views/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/4-authentication-and-permissions/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/5-relationships-and-hyperlinked-apis/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/6-viewsets-and-routers/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/7-schemas-and-client-libraries/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -65,163 +65,163 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/requests/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/responses/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/views/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/generic-views/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/viewsets/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/routers/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/parsers/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/renderers/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/serializers/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/fields/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/relations/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/validators/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/authentication/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/permissions/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/throttling/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/filtering/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/pagination/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/versioning/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/content-negotiation/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/metadata/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/schemas/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/format-suffixes/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/reverse/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/exceptions/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/status-codes/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/testing/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/settings/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -231,127 +231,127 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/documenting-your-api/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/api-clients/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/internationalization/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/ajax-csrf-cors/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/html-and-forms/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/browser-enhancements/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/browsable-api/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/rest-hypermedia-hateoas/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/third-party-resources/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/contributing/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/project-management/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.0-announcement/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.1-announcement/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.2-announcement/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.3-announcement/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.4-announcement/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.5-announcement/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/kickstarter-announcement/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/mozilla-grant/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/funding/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/release-notes/</loc>
|
||||
<lastmod>2016-12-12</lastmod>
|
||||
<lastmod>2017-01-06</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
|
|
@ -1115,9 +1115,9 @@ return Response(serializer.data)
|
|||
<p>If the request is omitted from the context, the returned URLs will be of the form <code>/url_path/filename.txt</code>.</p>
|
||||
<h4 id="throttle-headers-using-retry-after"><a class="toclink" href="#throttle-headers-using-retry-after">Throttle headers using <code>Retry-After</code>.</a></h4>
|
||||
<p>The custom <code>X-Throttle-Wait-Second</code> header has now been dropped in favor of the standard <code>Retry-After</code> header. You can revert this behavior if needed by writing a custom exception handler for your application.</p>
|
||||
<h4 id="date-and-time-objects-as-iso-8859-1-strings-in-serializer-data"><a class="toclink" href="#date-and-time-objects-as-iso-8859-1-strings-in-serializer-data">Date and time objects as ISO-8859-1 strings in serializer data.</a></h4>
|
||||
<h4 id="date-and-time-objects-as-iso-8601-strings-in-serializer-data"><a class="toclink" href="#date-and-time-objects-as-iso-8601-strings-in-serializer-data">Date and time objects as ISO-8601 strings in serializer data.</a></h4>
|
||||
<p>Date and Time objects are now coerced to strings by default in the serializer output. Previously they were returned as <code>Date</code>, <code>Time</code> and <code>DateTime</code> objects, and later coerced to strings by the renderer.</p>
|
||||
<p>You can modify this behavior globally by settings the existing <code>DATE_FORMAT</code>, <code>DATETIME_FORMAT</code> and <code>TIME_FORMAT</code> settings keys. Setting these values to <code>None</code> instead of their default value of <code>'iso-8859-1'</code> will result in native objects being returned in serializer data.</p>
|
||||
<p>You can modify this behavior globally by settings the existing <code>DATE_FORMAT</code>, <code>DATETIME_FORMAT</code> and <code>TIME_FORMAT</code> settings keys. Setting these values to <code>None</code> instead of their default value of <code>'iso-8601'</code> will result in native objects being returned in serializer data.</p>
|
||||
<pre><code>REST_FRAMEWORK = {
|
||||
# Return native `Date` and `Time` objects in `serializer.data`
|
||||
'DATETIME_FORMAT': None
|
||||
|
|
|
@ -419,6 +419,29 @@
|
|||
<p>Both this package and DRF docs are fully documented, well supported, and come highly recommended.</p>
|
||||
<p><img alt="Screenshot - Django REST Swagger" src="../../img/django-rest-swagger.png" /></p>
|
||||
<hr />
|
||||
<h3 id="drf-autodocs"><a class="toclink" href="#drf-autodocs">DRF AutoDocs</a></h3>
|
||||
<p>Oleksander Mashianovs' <a href="https://github.com/iMakedonsky/drf-autodocs">DRF Auto Docs</a> automated api renderer.</p>
|
||||
<p>Collects almost all the code you written into documentation effortlessly.</p>
|
||||
<p>Supports:</p>
|
||||
<ul>
|
||||
<li>functional view docs</li>
|
||||
<li>tree-like structure</li>
|
||||
<li>Docstrings:</li>
|
||||
<li>markdown</li>
|
||||
<li>preserve space & newlines</li>
|
||||
<li>formatting with nice syntax</li>
|
||||
<li>Fields:</li>
|
||||
<li>choices rendering</li>
|
||||
<li>help_text (to specify SerializerMethodField output, etc)</li>
|
||||
<li>smart read_only/required rendering</li>
|
||||
<li>Endpoint properties:</li>
|
||||
<li>filter_backends</li>
|
||||
<li>authentication_classes</li>
|
||||
<li>permission_classes</li>
|
||||
<li>extra url params(GET params)</li>
|
||||
</ul>
|
||||
<p><img alt="whole structure" src="http://joxi.ru/52aBGNI4k3oyA0.jpg" /></p>
|
||||
<hr />
|
||||
<h4 id="apiary"><a class="toclink" href="#apiary">Apiary</a></h4>
|
||||
<p>There are various other online tools and services for providing API documentation. One notable service is <a href="http://apiary.io/">Apiary</a>. With Apiary, you describe your API using a simple markdown-like syntax. The generated documentation includes API interaction, a mock server for testing & prototyping, and various other tools.</p>
|
||||
<p><img alt="Screenshot - Apiary" src="../../img/apiary.png" /></p>
|
||||
|
|
|
@ -528,6 +528,7 @@ You probably want to also tag the version now:
|
|||
<li><a href="https://github.com/etoccalino/django-rest-framework-httpsignature">djangorestframework-httpsignature</a> - Provides an easy to use HTTP Signature Authentication mechanism.</li>
|
||||
<li><a href="https://github.com/sunscrapers/djoser">djoser</a> - Provides a set of views to handle basic actions such as registration, login, logout, password reset and account activation.</li>
|
||||
<li><a href="https://github.com/Tivix/django-rest-auth/">django-rest-auth</a> - Provides a set of REST API endpoints for registration, authentication (including social media authentication), password reset, retrieve and update user details, etc.</li>
|
||||
<li><a href="https://github.com/ByteInternet/drf-oidc-auth">drf-oidc-auth</a> - Implements OpenID Connect token authentication for DRF.</li>
|
||||
</ul>
|
||||
<h3 id="permissions"><a class="toclink" href="#permissions">Permissions</a></h3>
|
||||
<ul>
|
||||
|
@ -542,7 +543,10 @@ You probably want to also tag the version now:
|
|||
<li><a href="https://github.com/djangonauts/django-rest-framework-gis">djangorestframework-gis</a> - Geographic add-ons</li>
|
||||
<li><a href="https://github.com/djangonauts/django-rest-framework-hstore">djangorestframework-hstore</a> - Serializer class to support django-hstore DictionaryField model field and its schema-mode feature.</li>
|
||||
<li><a href="https://github.com/django-json-api/django-rest-framework-json-api">djangorestframework-jsonapi</a> - Provides a parser, renderer, serializers, and other tools to help build an API that is compliant with the jsonapi.org spec.</li>
|
||||
<li><a href="https://github.com/wq/html-json-forms">html-json-forms</a>: Provides an algorithm and serializer to process HTML JSON Form submissions per the (inactive) spec.</li>
|
||||
<li><a href="https://github.com/wq/html-json-forms">html-json-forms</a> - Provides an algorithm and serializer to process HTML JSON Form submissions per the (inactive) spec.</li>
|
||||
<li><a href="https://github.com/evenicoulddoit/django-rest-framework-serializer-extensions">django-rest-framework-serializer-extensions</a> -
|
||||
Enables black/whitelisting fields, and conditionally expanding child serializers on a per-view/request basis.</li>
|
||||
<li><a href="https://github.com/wimglenn/djangorestframework-queryfields">djangorestframework-queryfields</a> - Serializer mixin allowing clients to control which fields will be sent in the API response.</li>
|
||||
</ul>
|
||||
<h3 id="serializer-fields"><a class="toclink" href="#serializer-fields">Serializer fields</a></h3>
|
||||
<ul>
|
||||
|
|
|
@ -460,6 +460,7 @@ cd tutorial
|
|||
'snippets.apps.SnippetsConfig',
|
||||
)
|
||||
</code></pre>
|
||||
<p>Please note that if you're using Django <1.9, you need to replace <code>snippets.apps.SnippetsConfig</code> with <code>snippets</code>.</p>
|
||||
<p>Okay, we're ready to roll.</p>
|
||||
<h2 id="creating-a-model-to-work-with"><a class="toclink" href="#creating-a-model-to-work-with">Creating a model to work with</a></h2>
|
||||
<p>For the purposes of this tutorial we're going to start by creating a simple <code>Snippet</code> model that is used to store code snippets. Go ahead and edit the <code>snippets/models.py</code> file. Note: Good programming practices include comments. Although you will find them in our repository version of this tutorial code, we have omitted them here to focus on the code itself.</p>
|
||||
|
|
Loading…
Reference in New Issue
Block a user