mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-25 02:53:58 +03:00
Deployed 3a7bfdf
with MkDocs version: 0.15.3
This commit is contained in:
parent
8a5bb6d5d7
commit
bd895fb63f
|
@ -617,6 +617,8 @@ urlpatterns += [
|
|||
<pre><code>{ 'token' : '9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b' }
|
||||
</code></pre>
|
||||
<p>Note that the default <code>obtain_auth_token</code> view explicitly uses JSON requests and responses, rather than using default renderer and parser classes in your settings. If you need a customized version of the <code>obtain_auth_token</code> view, you can do so by overriding the <code>ObtainAuthToken</code> view class, and using that in your url conf instead.</p>
|
||||
<p>By default there are no permissions or throttling applied to the <code>obtain_auth_token</code> view. If you do wish to apply throttling you'll need to override the view class,
|
||||
and include them using the <code>throttle_classes</code> attribute.</p>
|
||||
<h5 id="with-django-admin"><a class="toclink" href="#with-django-admin">With Django admin</a></h5>
|
||||
<p>It is also possible to create Tokens manually through admin interface. In case you are using a large user base, we recommend that you monkey patch the <code>TokenAdmin</code> class to customize it to your needs, more specifically by declaring the <code>user</code> field as <code>raw_field</code>.</p>
|
||||
<p><code>your_app/admin.py</code>:</p>
|
||||
|
@ -685,7 +687,7 @@ REST_FRAMEWORK = {
|
|||
)
|
||||
}
|
||||
</code></pre>
|
||||
<p>For more details see the <a href="https://django-oauth-toolkit.readthedocs.org/en/latest/rest-framework/getting_started.html">Django REST framework - Getting started</a> documentation.</p>
|
||||
<p>For more details see the <a href="https://django-oauth-toolkit.readthedocs.io/en/latest/rest-framework/getting_started.html">Django REST framework - Getting started</a> documentation.</p>
|
||||
<h2 id="django-rest-framework-oauth"><a class="toclink" href="#django-rest-framework-oauth">Django REST framework OAuth</a></h2>
|
||||
<p>The <a href="http://jpadilla.github.io/django-rest-framework-oauth/">Django REST framework OAuth</a> package provides both OAuth1 and OAuth2 support for REST framework.</p>
|
||||
<p>This package was previously included directly in REST framework but is now supported and maintained as a third party package.</p>
|
||||
|
@ -701,7 +703,7 @@ REST_FRAMEWORK = {
|
|||
<h2 id="json-web-token-authentication"><a class="toclink" href="#json-web-token-authentication">JSON Web Token Authentication</a></h2>
|
||||
<p>JSON Web Token is a fairly new standard which can be used for token-based authentication. Unlike the built-in TokenAuthentication scheme, JWT Authentication doesn't need to use a database to validate a token. <a href="https://github.com/GetBlimp">Blimp</a> maintains the <a href="https://github.com/GetBlimp/django-rest-framework-jwt">djangorestframework-jwt</a> package which provides a JWT Authentication class as well as a mechanism for clients to obtain a JWT given the username and password.</p>
|
||||
<h2 id="hawk-http-authentication"><a class="toclink" href="#hawk-http-authentication">Hawk HTTP Authentication</a></h2>
|
||||
<p>The <a href="http://hawkrest.readthedocs.org/en/latest/">HawkREST</a> library builds on the <a href="http://mohawk.readthedocs.org/en/latest/">Mohawk</a> library to let you work with <a href="https://github.com/hueniverse/hawk">Hawk</a> signed requests and responses in your API. <a href="https://github.com/hueniverse/hawk">Hawk</a> lets two parties securely communicate with each other using messages signed by a shared key. It is based on <a href="http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token-05">HTTP MAC access authentication</a> (which was based on parts of <a href="http://oauth.net/core/1.0a">OAuth 1.0</a>).</p>
|
||||
<p>The <a href="https://hawkrest.readthedocs.io/en/latest/">HawkREST</a> library builds on the <a href="https://mohawk.readthedocs.io/en/latest/">Mohawk</a> library to let you work with <a href="https://github.com/hueniverse/hawk">Hawk</a> signed requests and responses in your API. <a href="https://github.com/hueniverse/hawk">Hawk</a> lets two parties securely communicate with each other using messages signed by a shared key. It is based on <a href="http://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token-05">HTTP MAC access authentication</a> (which was based on parts of <a href="http://oauth.net/core/1.0a">OAuth 1.0</a>).</p>
|
||||
<h2 id="http-signature-authentication"><a class="toclink" href="#http-signature-authentication">HTTP Signature Authentication</a></h2>
|
||||
<p>HTTP Signature (currently a <a href="https://datatracker.ietf.org/doc/draft-cavage-http-signatures/">IETF draft</a>) provides a way to achieve origin authentication and message integrity for HTTP messages. Similar to <a href="http://docs.aws.amazon.com/general/latest/gr/signature-version-4.html">Amazon's HTTP Signature scheme</a>, used by many of its services, it permits stateless, per-request authentication. <a href="https://github.com/etoccalino/">Elvio Toccalino</a> maintains the <a href="https://github.com/etoccalino/django-rest-framework-httpsignature">djangorestframework-httpsignature</a> package which provides an easy to use HTTP Signature Authentication mechanism.</p>
|
||||
<h2 id="djoser"><a class="toclink" href="#djoser">Djoser</a></h2>
|
||||
|
|
|
@ -768,7 +768,7 @@ color_channel = serializers.ChoiceField(
|
|||
<p>Format strings may either be <a href="http://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior">Python strftime formats</a> which explicitly specify the format, or the special string <code>'iso-8601'</code>, which indicates that <a href="http://www.w3.org/TR/NOTE-datetime">ISO 8601</a> style datetimes should be used. (eg <code>'2013-01-29T12:34:56.000000Z'</code>)</p>
|
||||
<p>When a value of <code>None</code> is used for the format <code>datetime</code> objects will be returned by <code>to_representation</code> and the final output representation will determined by the renderer class.</p>
|
||||
<p>In the case of JSON this means the default datetime representation uses the <a href="http://ecma-international.org/ecma-262/5.1/#sec-15.9.1.15">ECMA 262 date time string specification</a>. This is a subset of ISO 8601 which uses millisecond precision, and includes the 'Z' suffix for the UTC timezone, for example: <code>2013-01-29T12:34:56.123Z</code>.</p>
|
||||
<h4 id="auto_now-and-auto_now_add-model-fields"><a class="toclink" href="#auto_now-and-auto_now_add-model-fields"><code>auto_now</code> and <code>auto_now_add</code> model fields.</a></h4>
|
||||
<h4 id="auto_now-and-auto_now_add-model-fields"><code>auto_now_add</code> model fields.<a class="toclink" href="#auto_now-and-auto_now_add-model-fields"><code>auto_now</code> and </a></h4>
|
||||
<p>When using <code>ModelSerializer</code> or <code>HyperlinkedModelSerializer</code>, note that any model fields with <code>auto_now=True</code> or <code>auto_now_add=True</code> will use serializer fields that are <code>read_only=True</code> by default.</p>
|
||||
<p>If you want to override this behavior, you'll need to declare the <code>DateTimeField</code> explicitly on the serializer. For example:</p>
|
||||
<pre><code>class CommentSerializer(serializers.ModelSerializer):
|
||||
|
@ -1022,7 +1022,7 @@ def to_internal_value(self, data):
|
|||
<h1 id="third-party-packages"><a class="toclink" href="#third-party-packages">Third party packages</a></h1>
|
||||
<p>The following third party packages are also available.</p>
|
||||
<h2 id="drf-compound-fields"><a class="toclink" href="#drf-compound-fields">DRF Compound Fields</a></h2>
|
||||
<p>The <a href="http://drf-compound-fields.readthedocs.org">drf-compound-fields</a> package provides "compound" serializer fields, such as lists of simple values, which can be described by other fields rather than serializers with the <code>many=True</code> option. Also provided are fields for typed dictionaries and values that can be either a specific type or a list of items of that type.</p>
|
||||
<p>The <a href="https://drf-compound-fields.readthedocs.io">drf-compound-fields</a> package provides "compound" serializer fields, such as lists of simple values, which can be described by other fields rather than serializers with the <code>many=True</code> option. Also provided are fields for typed dictionaries and values that can be either a specific type or a list of items of that type.</p>
|
||||
<h2 id="drf-extra-fields"><a class="toclink" href="#drf-extra-fields">DRF Extra Fields</a></h2>
|
||||
<p>The <a href="https://github.com/Hipo/drf-extra-fields">drf-extra-fields</a> package provides extra serializer fields for REST framework, including <code>Base64ImageField</code> and <code>PointField</code> classes.</p>
|
||||
<h2 id="djangrestframework-recursive"><a class="toclink" href="#djangrestframework-recursive">djangrestframework-recursive</a></h2>
|
||||
|
|
|
@ -536,7 +536,7 @@ from rest_framework import generics
|
|||
|
||||
class UserListView(generics.ListAPIView):
|
||||
queryset = User.objects.all()
|
||||
serializer = UserSerializer
|
||||
serializer_class = UserSerializer
|
||||
filter_backends = (filters.DjangoFilterBackend,)
|
||||
</code></pre>
|
||||
<h2 id="filtering-and-object-lookups"><a class="toclink" href="#filtering-and-object-lookups">Filtering and object lookups</a></h2>
|
||||
|
@ -639,7 +639,7 @@ class ProductFilter(filters.FilterSet):
|
|||
<p>And now you can execute:</p>
|
||||
<pre><code>http://example.com/api/products?manufacturer=foo
|
||||
</code></pre>
|
||||
<p>For more details on using filter sets see the <a href="https://django-filter.readthedocs.org/en/latest/index.html">django-filter documentation</a>.</p>
|
||||
<p>For more details on using filter sets see the <a href="https://django-filter.readthedocs.io/en/latest/index.html">django-filter documentation</a>.</p>
|
||||
<hr />
|
||||
<p><strong>Hints & Tips</strong></p>
|
||||
<ul>
|
||||
|
@ -656,7 +656,7 @@ class ProductFilter(filters.FilterSet):
|
|||
<p>The <code>SearchFilter</code> class will only be applied if the view has a <code>search_fields</code> attribute set. The <code>search_fields</code> attribute should be a list of names of text type fields on the model, such as <code>CharField</code> or <code>TextField</code>.</p>
|
||||
<pre><code>class UserListView(generics.ListAPIView):
|
||||
queryset = User.objects.all()
|
||||
serializer = UserSerializer
|
||||
serializer_class = UserSerializer
|
||||
filter_backends = (filters.SearchFilter,)
|
||||
search_fields = ('username', 'email')
|
||||
</code></pre>
|
||||
|
@ -723,7 +723,7 @@ class ProductFilter(filters.FilterSet):
|
|||
<p>The <code>ordering</code> attribute may be either a string or a list/tuple of strings.</p>
|
||||
<hr />
|
||||
<h2 id="djangoobjectpermissionsfilter"><a class="toclink" href="#djangoobjectpermissionsfilter">DjangoObjectPermissionsFilter</a></h2>
|
||||
<p>The <code>DjangoObjectPermissionsFilter</code> is intended to be used together with the <a href="https://django-guardian.readthedocs.org/"><code>django-guardian</code></a> package, with custom <code>'view'</code> permissions added. The filter will ensure that querysets only returns objects for which the user has the appropriate view permission.</p>
|
||||
<p>The <code>DjangoObjectPermissionsFilter</code> is intended to be used together with the <a href="https://django-guardian.readthedocs.io/"><code>django-guardian</code></a> package, with custom <code>'view'</code> permissions added. The filter will ensure that querysets only returns objects for which the user has the appropriate view permission.</p>
|
||||
<p>If you're using <code>DjangoObjectPermissionsFilter</code>, you'll probably also want to add an appropriate object permissions class, to ensure that users can only operate on instances if they have the appropriate object permissions. The easiest way to do this is to subclass <code>DjangoObjectPermissions</code> and add <code>'view'</code> permissions to the <code>perms_map</code> attribute.</p>
|
||||
<p>A complete example using both <code>DjangoObjectPermissionsFilter</code> and <code>DjangoObjectPermissions</code> might look something like this.</p>
|
||||
<p><strong>permissions.py</strong>:</p>
|
||||
|
@ -749,11 +749,11 @@ class ProductFilter(filters.FilterSet):
|
|||
'change' or 'delete' permissions.
|
||||
"""
|
||||
queryset = Event.objects.all()
|
||||
serializer = EventSerializer
|
||||
serializer_class = EventSerializer
|
||||
filter_backends = (filters.DjangoObjectPermissionsFilter,)
|
||||
permission_classes = (myapp.permissions.CustomObjectPermissions,)
|
||||
</code></pre>
|
||||
<p>For more information on adding <code>'view'</code> permissions for models, see the <a href="https://django-guardian.readthedocs.org/en/latest/userguide/assign.html">relevant section</a> of the <code>django-guardian</code> documentation, and <a href="http://blog.nyaruka.com/adding-a-view-permission-to-django-models">this blogpost</a>.</p>
|
||||
<p>For more information on adding <code>'view'</code> permissions for models, see the <a href="https://django-guardian.readthedocs.io/en/latest/userguide/assign.html">relevant section</a> of the <code>django-guardian</code> documentation, and <a href="http://blog.nyaruka.com/adding-a-view-permission-to-django-models">this blogpost</a>.</p>
|
||||
<hr />
|
||||
<h1 id="custom-generic-filtering"><a class="toclink" href="#custom-generic-filtering">Custom generic filtering</a></h1>
|
||||
<p>You can also provide your own generic filtering backend, or write an installable app for other developers to use.</p>
|
||||
|
|
|
@ -510,7 +510,8 @@ def example_view(request, format=None):
|
|||
<p><strong>.media_type</strong>: <code>multipart/form-data</code></p>
|
||||
<h2 id="fileuploadparser"><a class="toclink" href="#fileuploadparser">FileUploadParser</a></h2>
|
||||
<p>Parses raw file upload content. The <code>request.data</code> property will be a dictionary with a single key <code>'file'</code> containing the uploaded file.</p>
|
||||
<p>If the view used with <code>FileUploadParser</code> is called with a <code>filename</code> URL keyword argument, then that argument will be used as the filename. If it is called without a <code>filename</code> URL keyword argument, then the client must set the filename in the <code>Content-Disposition</code> HTTP header. For example <code>Content-Disposition: attachment; filename=upload.jpg</code>.</p>
|
||||
<p>If the view used with <code>FileUploadParser</code> is called with a <code>filename</code> URL keyword argument, then that argument will be used as the filename.</p>
|
||||
<p>If it is called without a <code>filename</code> URL keyword argument, then the client must set the filename in the <code>Content-Disposition</code> HTTP header. For example <code>Content-Disposition: attachment; filename=upload.jpg</code>.</p>
|
||||
<p><strong>.media_type</strong>: <code>*/*</code></p>
|
||||
<h5 id="notes"><a class="toclink" href="#notes">Notes:</a></h5>
|
||||
<ul>
|
||||
|
@ -519,7 +520,8 @@ def example_view(request, format=None):
|
|||
<li><code>FileUploadParser</code> respects Django's standard <code>FILE_UPLOAD_HANDLERS</code> setting, and the <code>request.upload_handlers</code> attribute. See the <a href="https://docs.djangoproject.com/en/dev/topics/http/file-uploads/#upload-handlers">Django documentation</a> for more details.</li>
|
||||
</ul>
|
||||
<h5 id="basic-usage-example"><a class="toclink" href="#basic-usage-example">Basic usage example:</a></h5>
|
||||
<pre><code>class FileUploadView(views.APIView):
|
||||
<pre><code># views.py
|
||||
class FileUploadView(views.APIView):
|
||||
parser_classes = (FileUploadParser,)
|
||||
|
||||
def put(self, request, filename, format=None):
|
||||
|
@ -528,6 +530,12 @@ def example_view(request, format=None):
|
|||
# do some stuff with uploaded file
|
||||
# ...
|
||||
return Response(status=204)
|
||||
|
||||
# urls.py
|
||||
urlpatterns = [
|
||||
# ...
|
||||
url(r'^upload/(?P<filename>[^/]+)$', FileUploadView.as_view())
|
||||
]
|
||||
</code></pre>
|
||||
<hr />
|
||||
<h1 id="custom-parsers"><a class="toclink" href="#custom-parsers">Custom parsers</a></h1>
|
||||
|
|
|
@ -442,6 +442,10 @@
|
|||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<a href="#absolute-and-relative-urls">Absolute and relative URLs</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#how-hyperlinked-views-are-determined">How hyperlinked views are determined</a>
|
||||
</li>
|
||||
|
@ -1060,6 +1064,20 @@ The default implementation raises an error, although subclasses may customize th
|
|||
model = Account
|
||||
fields = ('url', 'id', 'account_name', 'users', 'created')
|
||||
</code></pre>
|
||||
<h2 id="absolute-and-relative-urls"><a class="toclink" href="#absolute-and-relative-urls">Absolute and relative URLs</a></h2>
|
||||
<p>When instantiating a <code>HyperlinkedModelSerializer</code> you must include the current
|
||||
<code>request</code> in the serializer context, for example:</p>
|
||||
<pre><code>serializer = AccountSerializer(queryset, context={'request': request})
|
||||
</code></pre>
|
||||
<p>Doing so will ensure that the hyperlinks can include an appropriate hostname,
|
||||
so that the resulting representation uses fully qualified URLs, such as:</p>
|
||||
<pre><code>http://api.example.com/accounts/1/
|
||||
</code></pre>
|
||||
<p>Rather than relative URLs, such as:</p>
|
||||
<pre><code>/accounts/1/
|
||||
</code></pre>
|
||||
<p>If you <em>do</em> want to use relative URLs, you should explicitly pass <code>{'request': None}</code>
|
||||
in the serializer context.</p>
|
||||
<h2 id="how-hyperlinked-views-are-determined"><a class="toclink" href="#how-hyperlinked-views-are-determined">How hyperlinked views are determined</a></h2>
|
||||
<p>There needs to be a way of determining which views should be used for hyperlinking to model instances.</p>
|
||||
<p>By default hyperlinks are expected to correspond to a view name that matches the style <code>'{model_name}-detail'</code>, and looks up the instance by a <code>pk</code> keyword argument.</p>
|
||||
|
@ -1373,7 +1391,7 @@ def all_high_scores(request):
|
|||
<h1 id="third-party-packages"><a class="toclink" href="#third-party-packages">Third party packages</a></h1>
|
||||
<p>The following third party packages are also available.</p>
|
||||
<h2 id="django-rest-marshmallow"><a class="toclink" href="#django-rest-marshmallow">Django REST marshmallow</a></h2>
|
||||
<p>The <a href="http://tomchristie.github.io/django-rest-marshmallow/">django-rest-marshmallow</a> package provides an alternative implementation for serializers, using the python <a href="https://marshmallow.readthedocs.org/en/latest/">marshmallow</a> library. It exposes the same API as the REST framework serializers, and can be used as a drop-in replacement in some use-cases.</p>
|
||||
<p>The <a href="http://tomchristie.github.io/django-rest-marshmallow/">django-rest-marshmallow</a> package provides an alternative implementation for serializers, using the python <a href="https://marshmallow.readthedocs.io/en/latest/">marshmallow</a> library. It exposes the same API as the REST framework serializers, and can be used as a drop-in replacement in some use-cases.</p>
|
||||
<h2 id="serpy"><a class="toclink" href="#serpy">Serpy</a></h2>
|
||||
<p>The <a href="https://github.com/clarkduvall/serpy">serpy</a> package is an alternative implementation for serializers that is built for speed. <a href="https://github.com/clarkduvall/serpy">Serpy</a> serializes complex datatypes to simple native types. The native types can be easily converted to JSON or any other format needed.</p>
|
||||
<h2 id="mongoenginemodelserializer"><a class="toclink" href="#mongoenginemodelserializer">MongoengineModelSerializer</a></h2>
|
||||
|
|
|
@ -376,7 +376,7 @@
|
|||
|
||||
|
||||
<li class="main">
|
||||
<a href="#advanced-default-argument-usage">Advanced 'default' argument usage</a>
|
||||
<a href="#advanced-field-defaults">Advanced field defaults</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
@ -389,6 +389,24 @@
|
|||
</li>
|
||||
|
||||
|
||||
<li class="main">
|
||||
<a href="#limitations-of-validators">Limitations of validators</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<a href="#optional-fields">Optional fields</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#updating-nested-serializers">Updating nested serializers</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#debugging-complex-cases">Debugging complex cases</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="main">
|
||||
<a href="#writing-custom-validators">Writing custom validators</a>
|
||||
</li>
|
||||
|
@ -543,7 +561,7 @@ It has two required arguments, and a single optional <code>messages</code> argum
|
|||
<hr />
|
||||
<p><strong>Note</strong>: The <code>UniqueFor<Range>Validation</code> classes always imposes an implicit constraint that the fields they are applied to are always treated as required. Fields with <code>default</code> values are an exception to this as they always supply a value even when omitted from user input.</p>
|
||||
<hr />
|
||||
<h1 id="advanced-default-argument-usage"><a class="toclink" href="#advanced-default-argument-usage">Advanced 'default' argument usage</a></h1>
|
||||
<h1 id="advanced-field-defaults"><a class="toclink" href="#advanced-field-defaults">Advanced field defaults</a></h1>
|
||||
<p>Validators that are applied across multiple fields in the serializer can sometimes require a field input that should not be provided by the API client, but that <em>is</em> available as input to the validator.</p>
|
||||
<p>Two patterns that you may want to use for this sort of validation include:</p>
|
||||
<ul>
|
||||
|
@ -566,6 +584,56 @@ It has two required arguments, and a single optional <code>messages</code> argum
|
|||
)
|
||||
</code></pre>
|
||||
<hr />
|
||||
<h1 id="limitations-of-validators"><a class="toclink" href="#limitations-of-validators">Limitations of validators</a></h1>
|
||||
<p>There are some ambiguous cases where you'll need to instead handle validation
|
||||
explicitly, rather than relying on the default serializer classes that
|
||||
<code>ModelSerializer</code> generates.</p>
|
||||
<p>In these cases you may want to disable the automatically generated validators,
|
||||
by specifying an empty list for the serializer <code>Meta.validators</code> attribute.</p>
|
||||
<h2 id="optional-fields"><a class="toclink" href="#optional-fields">Optional fields</a></h2>
|
||||
<p>By default "unique together" validation enforces that all fields be
|
||||
<code>required=True</code>. In some cases, you might want to explicit apply
|
||||
<code>required=False</code> to one of the fields, in which case the desired behaviour
|
||||
of the validation is ambiguous.</p>
|
||||
<p>In this case you will typically need to exclude the validator from the
|
||||
serializer class, and instead write any validation logic explicitly, either
|
||||
in the <code>.validate()</code> method, or else in the view.</p>
|
||||
<p>For example:</p>
|
||||
<pre><code>class BillingRecordSerializer(serializers.ModelSerializer):
|
||||
def validate(self, data):
|
||||
# Apply custom validation either here, or in the view.
|
||||
|
||||
class Meta:
|
||||
fields = ('client', 'date', 'amount')
|
||||
extra_kwargs = {'client' {'required': 'False'}}
|
||||
validators = [] # Remove a default "unique together" constraint.
|
||||
</code></pre>
|
||||
<h2 id="updating-nested-serializers"><a class="toclink" href="#updating-nested-serializers">Updating nested serializers</a></h2>
|
||||
<p>When applying an update to an existing instance, uniqueness validators will
|
||||
exclude the current instance from the uniqueness check. The current instance
|
||||
is available in the context of the uniqueness check, because it exists as
|
||||
an attribute on the serializer, having initially been passed using
|
||||
<code>instance=...</code> when instantiating the serializer.</p>
|
||||
<p>In the case of update operations on <em>nested</em> serializers there's no way of
|
||||
applying this exclusion, because the instance is not available.</p>
|
||||
<p>Again, you'll probably want to explicitly remove the validator from the
|
||||
serializer class, and write the code the for the validation constraint
|
||||
explicitly, in a <code>.validate()</code> method, or in the view.</p>
|
||||
<h2 id="debugging-complex-cases"><a class="toclink" href="#debugging-complex-cases">Debugging complex cases</a></h2>
|
||||
<p>If you're not sure exactly what behavior a <code>ModelSerializer</code> class will
|
||||
generate it is usually a good idea to run <code>manage.py shell</code>, and print
|
||||
an instance of the serializer, so that you can inspect the fields and
|
||||
validators that it automatically generates for you.</p>
|
||||
<pre><code>>>> serializer = MyComplexModelSerializer()
|
||||
>>> print(serializer)
|
||||
class MyComplexModelSerializer:
|
||||
my_fields = ...
|
||||
</code></pre>
|
||||
<p>Also keep in mind that with complex cases it can often be better to explicitly
|
||||
define your serializer classes, rather than relying on the default
|
||||
<code>ModelSerializer</code> behavior. This involves a little more code, but ensures
|
||||
that the resulting behavior is more transparent.</p>
|
||||
<hr />
|
||||
<h1 id="writing-custom-validators"><a class="toclink" href="#writing-custom-validators">Writing custom validators</a></h1>
|
||||
<p>You can use any of Django's existing validators, or write your own custom validators.</p>
|
||||
<h2 id="function-based"><a class="toclink" href="#function-based">Function based</a></h2>
|
||||
|
|
172
base.html
Normal file
172
base.html
Normal file
|
@ -0,0 +1,172 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>{% if page_title %}{{ page_title }} - {% endif %}{{ site_name }}</title>
|
||||
<link href="{{ base_url }}/img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="{{ canonical_url }}" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST{% if current_page %}, {{ current_page.title }}{% endif %}">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
||||
<!-- Le styles -->
|
||||
<link href="{{ base_url }}/css/prettify.css" rel="stylesheet">
|
||||
<link href="{{ base_url }}/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="{{ base_url }}/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="{{ base_url }}/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-18852272-2']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function() {
|
||||
var ga = document.createElement('script');
|
||||
ga.type = 'text/javascript';
|
||||
ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
#sidebarInclude img {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
#sidebarInclude a.promo {
|
||||
color: black;
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
div.promo {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="prettyPrint()" class="{% if current_page and current_page.is_homepage %}index{% endif %}-page">
|
||||
|
||||
<div class="wrapper">
|
||||
{% include "nav.html" %}
|
||||
|
||||
<div class="body-content">
|
||||
<div class="container-fluid">
|
||||
<!-- Search Modal -->
|
||||
<div id="mkdocs_search_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3 id="myModalLabel">Documentation search</h3>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<form role="form" autocomplete="off">
|
||||
<div class="form-group">
|
||||
<input type="text" name="q" class="form-control" placeholder="Search..." id="mkdocs-search-query">
|
||||
</div>
|
||||
</form>
|
||||
<div id="mkdocs-search-results"></div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span3">
|
||||
<div id="table-of-contents">
|
||||
<ul class="nav nav-list side-nav well sidebar-nav-fixed">
|
||||
{% if current_page and current_page.is_homepage %}
|
||||
<li class="main">
|
||||
<a href="#">Django REST framework</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% for toc_item in toc %}
|
||||
<li class="{% if current_page and not current_page.is_homepage %}main{% endif %}">
|
||||
<a href="{{ toc_item.url }}">{{ toc_item.title }}</a>
|
||||
</li>
|
||||
|
||||
{% for toc_item in toc_item.children %}
|
||||
<li>
|
||||
<a href="{{ toc_item.url }}">{{ toc_item.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% endfor %}
|
||||
|
||||
<div class="promo">
|
||||
<hr/>
|
||||
<div id="sidebarInclude">
|
||||
</div>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="main-content" class="span9">
|
||||
{% block content %}
|
||||
{% if meta.source %}
|
||||
{% for filename in meta.source %}
|
||||
<a class="github" href="https://github.com/tomchristie/django-rest-framework/tree/master/rest_framework/{{ filename }}">
|
||||
<span class="label label-info">{{ filename }}</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
|
||||
{{ content }}
|
||||
{% endblock %}
|
||||
|
||||
</div> <!--/span-->
|
||||
</div> <!--/row-->
|
||||
</div> <!--/.fluid-container-->
|
||||
</div> <!--/.body content-->
|
||||
<div id="push"></div>
|
||||
</div> <!--/.wrapper -->
|
||||
|
||||
<footer class="span12">
|
||||
<p>Documentation built with <a href="http://www.mkdocs.org/">MkDocs</a>.
|
||||
</p>
|
||||
</footer>
|
||||
|
||||
<!-- Le javascript
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
<script src="{{ base_url }}/js/jquery-1.8.1-min.js"></script>
|
||||
<script src="{{ base_url }}/js/prettify-1.0.js"></script>
|
||||
<script src="{{ base_url }}/js/bootstrap-2.1.1-min.js"></script>
|
||||
<script src="https://fund.django-rest-framework.org/sidebar_include.js"></script>
|
||||
<script>var base_url = '{{ base_url }}';</script>
|
||||
<script src="{{ base_url }}/mkdocs/js/require.js"></script>
|
||||
<script src="{{ base_url }}/js/theme.js"></script>
|
||||
|
||||
<script>
|
||||
var shiftWindow = function() {
|
||||
scrollBy(0, -50)
|
||||
};
|
||||
|
||||
if (location.hash) shiftWindow();
|
||||
window.addEventListener("hashchange", shiftWindow);
|
||||
|
||||
$('.dropdown-menu').on('click touchstart', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
// Dynamically force sidenav/dropdown to no higher than browser window
|
||||
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
|
||||
|
||||
$(function() {
|
||||
$(window).resize(function() {
|
||||
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
0
css/bootstrap-responsive.css
vendored
Normal file → Executable file
0
css/bootstrap-responsive.css
vendored
Normal file → Executable file
0
css/bootstrap.css
vendored
Normal file → Executable file
0
css/bootstrap.css
vendored
Normal file → Executable file
BIN
img/premium/rover-readme.png
Normal file
BIN
img/premium/rover-readme.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 64 KiB |
BIN
img/premium/sentry-readme.png
Normal file
BIN
img/premium/sentry-readme.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
56
index.html
56
index.html
|
@ -349,6 +349,12 @@
|
|||
|
||||
|
||||
|
||||
<li class="">
|
||||
<a href="#funding">Funding</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<li class="">
|
||||
<a href="#requirements">Requirements</a>
|
||||
</li>
|
||||
|
@ -429,6 +435,25 @@
|
|||
|
||||
|
||||
|
||||
<style>
|
||||
.promo li a {
|
||||
float: left;
|
||||
width: 130px;
|
||||
height: 20px;
|
||||
text-align: center;
|
||||
margin: 10px 30px;
|
||||
padding: 150px 0 0 0;
|
||||
background-position: 0 50%;
|
||||
background-size: 130px auto;
|
||||
background-repeat: no-repeat;
|
||||
font-size: 120%;
|
||||
color: black;
|
||||
}
|
||||
.promo li {
|
||||
list-style: none;
|
||||
}
|
||||
</style>
|
||||
|
||||
<p class="badges" height=20px>
|
||||
<iframe src="http://ghbtns.com/github-btn.html?user=tomchristie&repo=django-rest-framework&type=watch&count=true" class="github-star-button" allowtransparency="true" frameborder="0" scrolling="0" width="110px" height="20px"></iframe>
|
||||
|
||||
|
@ -465,22 +490,25 @@
|
|||
<li><a href="api-guide/serializers/">Serialization</a> that supports both <a href="./api-guide/serializers#modelserializer">ORM</a> and <a href="./api-guide/serializers#serializers">non-ORM</a> data sources.</li>
|
||||
<li>Customizable all the way down - just use <a href="./api-guide/views#function-based-views">regular function-based views</a> if you don't need the <a href="api-guide/generic-views/">more</a> <a href="api-guide/viewsets/">powerful</a> <a href="api-guide/routers/">features</a>.</li>
|
||||
<li><a href="./.">Extensive documentation</a>, and <a href="https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework">great community support</a>.</li>
|
||||
<li>Used and trusted by large companies such as <a href="http://www.mozilla.org/en-US/about/">Mozilla</a> and <a href="https://www.eventbrite.co.uk/about/">Eventbrite</a>.</li>
|
||||
<li>Used and trusted by internationally recognised companies including <a href="http://www.mozilla.org/en-US/about/">Mozilla</a>, <a href="https://www.redhat.com/">Red Hat</a>, <a href="https://www.heroku.com/">Heroku</a>, and <a href="https://www.eventbrite.co.uk/about/">Eventbrite</a>.</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<p>We are a <a href="https://fund.django-rest-framework.org/topics/funding/">collaboratively funded project</a>.
|
||||
Many thanks to our sponsors for ensuring we can continue to develop, support and improve Django REST framework.</p>
|
||||
<p><a href="https://www.rover.com/" rel="nofollow" style="background-image:url(./img/rover.png);
|
||||
display:block;
|
||||
width: 300px;
|
||||
height: 0px;
|
||||
text-align: center;
|
||||
margin: 10px auto 30px;
|
||||
padding: 300px 0 0 0;
|
||||
background-position: 0 50%;
|
||||
background-size: 280px auto;
|
||||
background-repeat: no-repeat;
|
||||
font-size: 150%;">Rover.com</a></p>
|
||||
<h2 id="funding"><a class="toclink" href="#funding">Funding</a></h2>
|
||||
<p>REST framework is a <em>collaboratively funded project</em>. If you use
|
||||
REST framework commercially we strongly encourage you to invest in its
|
||||
continued development by <strong><a href="topics/funding/">signing up for a paid plan</a></strong>.</p>
|
||||
<p>The initial aim is to provide a single full-time position on REST framework.
|
||||
Right now we're a little over 43% of the way towards achieving that.
|
||||
<em>Every single sign-up makes a significant impact.</em> Taking out a
|
||||
<a href="https://fund.django-rest-framework.org/topics/funding/#corporate-plans">basic tier sponsorship</a> moves us about 1% closer to our funding target.</p>
|
||||
<ul class="premium-promo promo">
|
||||
<li><a href="http://jobs.rover.com/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rover_130x130.png)">Rover.com</a></li>
|
||||
<li><a href="https://getsentry.com/welcome/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/sentry130.png)">Sentry</a></li>
|
||||
</ul>
|
||||
|
||||
<div style="clear: both; padding-bottom: 20px;"></div>
|
||||
|
||||
<p><em>Many thanks to all our <a href="https://fund.django-rest-framework.org/topics/funding/#our-sponsors">awesome sponsors</a>, and in particular to our premium backers, <a href="http://jobs.rover.com/">Rover</a> and <a href="https://getsentry.com/welcome/">Sentry</a>.</em></p>
|
||||
<hr />
|
||||
<h2 id="requirements"><a class="toclink" href="#requirements">Requirements</a></h2>
|
||||
<p>REST framework requires the following:</p>
|
||||
|
|
0
js/bootstrap-2.1.1-min.js
vendored
Normal file → Executable file
0
js/bootstrap-2.1.1-min.js
vendored
Normal file → Executable file
|
@ -15,7 +15,7 @@ require([
|
|||
var sParameterName = sURLVariables[i].split('=');
|
||||
if (sParameterName[0] == 'q')
|
||||
{
|
||||
return sParameterName[1];
|
||||
return decodeURIComponent(sParameterName[1].replace(/\+/g, '%20'));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
File diff suppressed because one or more lines are too long
46
nav.html
Normal file
46
nav.html
Normal file
|
@ -0,0 +1,46 @@
|
|||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/tomchristie/django-rest-framework/tree/master">GitHub</a>
|
||||
<a class="repo-link btn btn-inverse btn-small {% if not next_page %}disabled{% endif %}" rel="prev" {% if next_page %}href="{{ next_page.url }}"{% endif %}>
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small {% if not previous_page %}disabled{% endif %}" rel="next" {% if previous_page %}href="{{ previous_page.url }}"{% endif %}>
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
{% if include_nav %}
|
||||
<!-- Main navigation -->
|
||||
<ul class="nav navbar-nav">
|
||||
{% for nav_item in nav %} {% if nav_item.children %}
|
||||
<li class="dropdown{% if nav_item.active %} active{% endif %}">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">{{ nav_item.title }} <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
{% for nav_item in nav_item.children %}
|
||||
<li {% if nav_item.active %}class="active" {% endif %}>
|
||||
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</li>
|
||||
{% else %}
|
||||
<li {% if nav_item.active %}class="active" {% endif %}>
|
||||
<a href="{{ nav_item.url }}">{{ nav_item.title }}</a>
|
||||
</li>
|
||||
{% endif %} {% endfor %}
|
||||
|
||||
</ul>
|
||||
{% endif %}
|
||||
</div>
|
||||
<!--/.nav-collapse -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
104
sitemap.xml
104
sitemap.xml
|
@ -4,7 +4,7 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -13,43 +13,43 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/quickstart/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/1-serialization/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/2-requests-and-responses/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/3-class-based-views/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/4-authentication-and-permissions/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/5-relationships-and-hyperlinked-apis/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//tutorial/6-viewsets-and-routers/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -59,157 +59,157 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/requests/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/responses/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/views/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/generic-views/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/viewsets/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/routers/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/parsers/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/renderers/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/serializers/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/fields/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/relations/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/validators/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/authentication/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/permissions/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/throttling/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/filtering/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/pagination/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/versioning/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/content-negotiation/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/metadata/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/format-suffixes/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/reverse/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/exceptions/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/status-codes/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/testing/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//api-guide/settings/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
@ -219,109 +219,109 @@
|
|||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/documenting-your-api/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/internationalization/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/ajax-csrf-cors/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/html-and-forms/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/browser-enhancements/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/browsable-api/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/rest-hypermedia-hateoas/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/third-party-resources/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/contributing/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/project-management/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.0-announcement/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.1-announcement/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.2-announcement/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/3.3-announcement/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/kickstarter-announcement/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/mozilla-grant/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/funding/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
<url>
|
||||
<loc>http://www.django-rest-framework.org//topics/release-notes/</loc>
|
||||
<lastmod>2016-05-28</lastmod>
|
||||
<lastmod>2016-06-24</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
|
||||
|
|
|
@ -434,7 +434,7 @@
|
|||
<hr />
|
||||
<p><em>Below is an in-depth guide to the API changes and migration notes for 3.0.</em></p>
|
||||
<h2 id="request-objects"><a class="toclink" href="#request-objects">Request objects</a></h2>
|
||||
<h4 id="the-data-and-query_params-properties"><a class="toclink" href="#the-data-and-query_params-properties">The <code>.data</code> and <code>.query_params</code> properties.</a></h4>
|
||||
<h4 id="the-data-and-query_params-properties"><code>.query_params</code> properties.<a class="toclink" href="#the-data-and-query_params-properties">The <code>.data</code> and </a></h4>
|
||||
<p>The usage of <code>request.DATA</code> and <code>request.FILES</code> is now pending deprecation in favor of a single <code>request.data</code> attribute that contains <em>all</em> the parsed data.</p>
|
||||
<p>Having separate attributes is reasonable for web applications that only ever parse url-encoded or multipart requests, but makes less sense for the general-purpose request parsing that REST framework supports.</p>
|
||||
<p>You may now pass all the request data to a serializer class in a single argument:</p>
|
||||
|
@ -466,7 +466,7 @@ ExampleSerializer(data=request.DATA, files=request.FILES)
|
|||
<li>Calling <code>serializer.save()</code> then saves and returns the new object instance.</li>
|
||||
</ol>
|
||||
<p>The resulting API changes are further detailed below.</p>
|
||||
<h4 id="the-create-and-update-methods"><a class="toclink" href="#the-create-and-update-methods">The <code>.create()</code> and <code>.update()</code> methods.</a></h4>
|
||||
<h4 id="the-create-and-update-methods"><code>.update()</code> methods.<a class="toclink" href="#the-create-and-update-methods">The <code>.create()</code> and </a></h4>
|
||||
<p>The <code>.restore_object()</code> method is now removed, and we instead have two separate methods, <code>.create()</code> and <code>.update()</code>. These methods work slightly different to the previous <code>.restore_object()</code>.</p>
|
||||
<p>When using the <code>.create()</code> and <code>.update()</code> methods you should both create <em>and save</em> the object instance. This is in contrast to the previous <code>.restore_object()</code> behavior that would instantiate the object but not save it.</p>
|
||||
<p>These methods also replace the optional <code>.save_object()</code> method, which no longer exists.</p>
|
||||
|
@ -498,7 +498,7 @@ def create(self, validated_data):
|
|||
return Snippet.objects.create(**validated_data)
|
||||
</code></pre>
|
||||
<p>Note that these methods should return the newly created object instance.</p>
|
||||
<h4 id="use-validated_data-instead-of-object"><a class="toclink" href="#use-validated_data-instead-of-object">Use <code>.validated_data</code> instead of <code>.object</code>.</a></h4>
|
||||
<h4 id="use-validated_data-instead-of-object"><code>.object</code>.<a class="toclink" href="#use-validated_data-instead-of-object">Use <code>.validated_data</code> instead of </a></h4>
|
||||
<p>You must now use the <code>.validated_data</code> attribute if you need to inspect the data before saving, rather than using the <code>.object</code> attribute, which no longer exists.</p>
|
||||
<p>For example the following code <em>is no longer valid</em>:</p>
|
||||
<pre><code>if serializer.is_valid():
|
||||
|
@ -846,7 +846,7 @@ def all_high_scores(request):
|
|||
</code></pre>
|
||||
<hr />
|
||||
<h2 id="serializer-fields"><a class="toclink" href="#serializer-fields">Serializer fields</a></h2>
|
||||
<h4 id="the-field-and-readonly-field-classes"><a class="toclink" href="#the-field-and-readonly-field-classes">The <code>Field</code> and <code>ReadOnly</code> field classes.</a></h4>
|
||||
<h4 id="the-field-and-readonly-field-classes"><code>ReadOnly</code> field classes.<a class="toclink" href="#the-field-and-readonly-field-classes">The <code>Field</code> and </a></h4>
|
||||
<p>There are some minor tweaks to the field base classes.</p>
|
||||
<p>Previously we had these two base classes:</p>
|
||||
<ul>
|
||||
|
@ -858,7 +858,7 @@ def all_high_scores(request):
|
|||
<li><code>Field</code> is the base class for all fields. It does not include any default implementation for either serializing or deserializing data.</li>
|
||||
<li><code>ReadOnlyField</code> is a concrete implementation for read-only fields that simply returns the attribute value without modification.</li>
|
||||
</ul>
|
||||
<h4 id="the-required-allow_null-allow_blank-and-default-arguments"><a class="toclink" href="#the-required-allow_null-allow_blank-and-default-arguments">The <code>required</code>, <code>allow_null</code>, <code>allow_blank</code> and <code>default</code> arguments.</a></h4>
|
||||
<h4 id="the-required-allow_null-allow_blank-and-default-arguments"><code>allow_null</code>, <code>default</code> arguments.<a class="toclink" href="#the-required-allow_null-allow_blank-and-default-arguments">The <code>required</code>, <code>allow_blank</code> and </a></h4>
|
||||
<p>REST framework now has more explicit and clear control over validating empty values for fields.</p>
|
||||
<p>Previously the meaning of the <code>required=False</code> keyword argument was underspecified. In practice its use meant that a field could either be not included in the input, or it could be included, but be <code>None</code> or the empty string.</p>
|
||||
<p>We now have a better separation, with separate <code>required</code>, <code>allow_null</code> and <code>allow_blank</code> arguments.</p>
|
||||
|
@ -968,7 +968,7 @@ This removes some magic and makes it easier and more obvious to move between imp
|
|||
<p>The following usage will <em>now raise an error</em>:</p>
|
||||
<pre><code>email = serializers.EmailField(source='email')
|
||||
</code></pre>
|
||||
<h4 id="the-uniquevalidator-and-uniquetogethervalidator-classes"><a class="toclink" href="#the-uniquevalidator-and-uniquetogethervalidator-classes">The <code>UniqueValidator</code> and <code>UniqueTogetherValidator</code> classes.</a></h4>
|
||||
<h4 id="the-uniquevalidator-and-uniquetogethervalidator-classes"><code>UniqueTogetherValidator</code> classes.<a class="toclink" href="#the-uniquevalidator-and-uniquetogethervalidator-classes">The <code>UniqueValidator</code> and </a></h4>
|
||||
<p>REST framework now provides new validators that allow you to ensure field uniqueness, while still using a completely explicit <code>Serializer</code> class instead of using <code>ModelSerializer</code>.</p>
|
||||
<p>The <code>UniqueValidator</code> should be applied to a serializer field, and takes a single <code>queryset</code> argument.</p>
|
||||
<pre><code>from rest_framework import serializers
|
||||
|
|
|
@ -346,7 +346,7 @@
|
|||
|
||||
|
||||
<li class="main">
|
||||
<a href="#working-with-ajax-csrf-cors">Working with AJAX, CSRF CORS</a>
|
||||
<a href="#working-with-ajax-csrf-cors">Working with AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
|
|
@ -492,7 +492,7 @@ pip install -r requirements.txt
|
|||
</code></pre>
|
||||
<p>Note: The test case and test method matching is fuzzy and will sometimes run other tests that contain a partial string match to the given command line input.</p>
|
||||
<h3 id="running-against-multiple-environments"><a class="toclink" href="#running-against-multiple-environments">Running against multiple environments</a></h3>
|
||||
<p>You can also use the excellent <a href="http://tox.readthedocs.org/en/latest/">tox</a> testing tool to run the tests against all supported versions of Python and Django. Install <code>tox</code> globally, and then simply run:</p>
|
||||
<p>You can also use the excellent <a href="https://tox.readthedocs.io/en/latest/">tox</a> testing tool to run the tests against all supported versions of Python and Django. Install <code>tox</code> globally, and then simply run:</p>
|
||||
<pre><code>tox
|
||||
</code></pre>
|
||||
<h2 id="pull-requests"><a class="toclink" href="#pull-requests">Pull requests</a></h2>
|
||||
|
|
|
@ -346,7 +346,7 @@
|
|||
|
||||
|
||||
<li class="main">
|
||||
<a href="#html-forms">HTML Forms</a>
|
||||
<a href="#html-forms">HTML & Forms</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
|
|
@ -380,7 +380,7 @@
|
|||
<h1 id="mozilla-grant"><a class="toclink" href="#mozilla-grant">Mozilla Grant</a></h1>
|
||||
<p>We have recently been <a href="https://blog.mozilla.org/blog/2016/04/13/mozilla-open-source-support-moss-update-q1-2016/">awarded a Mozilla grant</a>, in order to fund the next major releases of REST framework. This work will focus on seamless client-side integration by introducing supporting client libraries that are able to dynamically interact with REST framework APIs. The framework will provide for either hypermedia or schema endpoints, which will expose the available interface for the client libraries to interact with.</p>
|
||||
<p>Additionally, we will be building on the realtime support that Django Channels provides, supporting and documenting how to build realtime APIs with REST framework. Again, this will include supporting work in the associated client libraries, making it easier to build richly interactive applications.</p>
|
||||
<p>The <a href="../www.coreapi.org">Core API</a> project will provide the foundations for our client library support, and will allow us to support interaction using a wide range of schemas and hypermedia formats. It's worth noting that these client libraries won't be tightly coupled to solely REST framework APIs either, and will be able to interact with <em>any</em> API that exposes a supported schema or hypermedia format.</p>
|
||||
<p>The <a href="http://www.coreapi.org">Core API</a> project will provide the foundations for our client library support, and will allow us to support interaction using a wide range of schemas and hypermedia formats. It's worth noting that these client libraries won't be tightly coupled to solely REST framework APIs either, and will be able to interact with <em>any</em> API that exposes a supported schema or hypermedia format.</p>
|
||||
<p>Specifically, the work includes:</p>
|
||||
<h2 id="client-libraries"><a class="toclink" href="#client-libraries">Client libraries</a></h2>
|
||||
<p>This work will include built-in schema and hypermedia support, allowing dynamic client libraries to interact with the API. I'll also be releasing both Python and Javascript client libraries, plus a command-line client, a new tutorial section, and further documentation.</p>
|
||||
|
|
|
@ -346,7 +346,7 @@
|
|||
|
||||
|
||||
<li class="main">
|
||||
<a href="#rest-hypermedia-hateoas">REST, Hypermedia HATEOAS</a>
|
||||
<a href="#rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
|
|
@ -470,7 +470,7 @@ You probably want to also tag the version now:
|
|||
<p>Shorter form to run the tests for a given test method.</p>
|
||||
<pre><code>$ ./runtests.py test_this_method
|
||||
</code></pre>
|
||||
<p>To run your tests against multiple versions of Python as different versions of requirements such as Django we recommend using <code>tox</code>. <a href="https://tox.readthedocs.org/en/latest/">Tox</a> is a generic virtualenv management and test command line tool.</p>
|
||||
<p>To run your tests against multiple versions of Python as different versions of requirements such as Django we recommend using <code>tox</code>. <a href="https://tox.readthedocs.io/en/latest/">Tox</a> is a generic virtualenv management and test command line tool.</p>
|
||||
<p>First, install <code>tox</code> globally.</p>
|
||||
<pre><code>$ pip install tox
|
||||
</code></pre>
|
||||
|
@ -528,7 +528,7 @@ You probably want to also tag the version now:
|
|||
<ul>
|
||||
<li><a href="https://github.com/estebistec/drf-compound-fields">drf-compound-fields</a> - Provides "compound" serializer fields, such as lists of simple values.</li>
|
||||
<li><a href="https://github.com/Hipo/drf-extra-fields">django-extra-fields</a> - Provides extra serializer fields.</li>
|
||||
<li><a href="https://github.com/WGBH/django-versatileimagefield">django-versatileimagefield</a> - Provides a drop-in replacement for Django's stock <code>ImageField</code> that makes it easy to serve images in multiple sizes/renditions from a single field. For DRF-specific implementation docs, <a href="http://django-versatileimagefield.readthedocs.org/en/latest/drf_integration.html">click here</a>.</li>
|
||||
<li><a href="https://github.com/WGBH/django-versatileimagefield">django-versatileimagefield</a> - Provides a drop-in replacement for Django's stock <code>ImageField</code> that makes it easy to serve images in multiple sizes/renditions from a single field. For DRF-specific implementation docs, <a href="https://django-versatileimagefield.readthedocs.io/en/latest/drf_integration.html">click here</a>.</li>
|
||||
</ul>
|
||||
<h3 id="views"><a class="toclink" href="#views">Views</a></h3>
|
||||
<ul>
|
||||
|
@ -567,10 +567,10 @@ You probably want to also tag the version now:
|
|||
<li><a href="https://github.com/AppsFuel/gaiarestframework">gaiarestframework</a> - Utils for django-rest-framework</li>
|
||||
<li><a href="https://github.com/chibisov/drf-extensions">drf-extensions</a> - A collection of custom extensions</li>
|
||||
<li><a href="https://github.com/dustinfarris/ember-django-adapter">ember-django-adapter</a> - An adapter for working with Ember.js</li>
|
||||
<li><a href="https://github.com/WGBH/django-versatileimagefield">django-versatileimagefield</a> - Provides a drop-in replacement for Django's stock <code>ImageField</code> that makes it easy to serve images in multiple sizes/renditions from a single field. For DRF-specific implementation docs, <a href="http://django-versatileimagefield.readthedocs.org/en/latest/drf_integration.html">click here</a>.</li>
|
||||
<li><a href="https://github.com/WGBH/django-versatileimagefield">django-versatileimagefield</a> - Provides a drop-in replacement for Django's stock <code>ImageField</code> that makes it easy to serve images in multiple sizes/renditions from a single field. For DRF-specific implementation docs, <a href="https://django-versatileimagefield.readthedocs.io/en/latest/drf_integration.html">click here</a>.</li>
|
||||
<li><a href="https://github.com/aschn/drf-tracking">drf-tracking</a> - Utilities to track requests to DRF API views.</li>
|
||||
<li><a href="https://github.com/dealertrack/django-rest-framework-braces">django-rest-framework-braces</a> - Collection of utilities for working with Django Rest Framework. The most notable ones are <a href="https://django-rest-framework-braces.readthedocs.org/en/latest/overview.html#formserializer">FormSerializer</a> and <a href="https://django-rest-framework-braces.readthedocs.org/en/latest/overview.html#serializerform">SerializerForm</a>, which are adapters between DRF serializers and Django forms.</li>
|
||||
<li><a href="http://drf-haystack.readthedocs.org/en/latest/">drf-haystack</a> - Haystack search for Django Rest Framework</li>
|
||||
<li><a href="https://github.com/dealertrack/django-rest-framework-braces">django-rest-framework-braces</a> - Collection of utilities for working with Django Rest Framework. The most notable ones are <a href="https://django-rest-framework-braces.readthedocs.io/en/latest/overview.html#formserializer">FormSerializer</a> and <a href="https://django-rest-framework-braces.readthedocs.io/en/latest/overview.html#serializerform">SerializerForm</a>, which are adapters between DRF serializers and Django forms.</li>
|
||||
<li><a href="https://drf-haystack.readthedocs.io/en/latest/">drf-haystack</a> - Haystack search for Django Rest Framework</li>
|
||||
<li><a href="https://github.com/mrhwick/django-rest-framework-version-transforms">django-rest-framework-version-transforms</a> - Enables the use of delta transformations for versioning of DRF resource representations.</li>
|
||||
<li><a href="https://github.com/raphaelgyory/django-rest-messaging">django-rest-messaging</a>, <a href="https://github.com/raphaelgyory/django-rest-messaging-centrifugo">django-rest-messaging-centrifugo</a> and <a href="https://github.com/raphaelgyory/django-rest-messaging-js">django-rest-messaging-js</a> - A real-time pluggable messaging service using DRM.</li>
|
||||
</ul>
|
||||
|
@ -585,6 +585,7 @@ You probably want to also tag the version now:
|
|||
<li><a href="https://godjango.com/45-viewsets-and-routers-django-rest-framework-part-3/">ViewSets and Routers - django-rest-framework part 3</a></li>
|
||||
<li><a href="http://richardtier.com/2014/02/25/django-rest-framework-user-endpoint/">Django Rest Framework User Endpoint</a></li>
|
||||
<li><a href="http://richardtier.com/2014/03/06/110/">Check credentials using Django Rest Framework</a></li>
|
||||
<li><a href="https://teamtreehouse.com/library/django-rest-framework">Django REST Framework course</a></li>
|
||||
</ul>
|
||||
<h3 id="videos"><a class="toclink" href="#videos">Videos</a></h3>
|
||||
<ul>
|
||||
|
|
|
@ -555,6 +555,7 @@ http --json POST http://127.0.0.1:8000/snippets/ code="print 456"
|
|||
"style": "friendly"
|
||||
}
|
||||
</code></pre>
|
||||
<p>If you add a <code>--debug</code> switch to the <code>http</code> requests above, you will be able to see the request type in request headers.</p>
|
||||
<p>Now go and open the API in a web browser, by visiting <a href="http://127.0.0.1:8000/snippets/">http://127.0.0.1:8000/snippets/</a>.</p>
|
||||
<h3 id="browsability"><a class="toclink" href="#browsability">Browsability</a></h3>
|
||||
<p>Because the API chooses the content type of the response based on the client request, it will, by default, return an HTML-formatted representation of the resource when that resource is requested by a web browser. This allows for the API to return a fully web-browsable HTML representation.</p>
|
||||
|
|
|
@ -346,7 +346,7 @@
|
|||
|
||||
|
||||
<li class="main">
|
||||
<a href="#tutorial-4-authentication-permissions">Tutorial 4: Authentication Permissions</a>
|
||||
<a href="#tutorial-4-authentication-permissions">Tutorial 4: Authentication & Permissions</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@
|
|||
|
||||
|
||||
<li class="main">
|
||||
<a href="#tutorial-5-relationships-hyperlinked-apis">Tutorial 5: Relationships Hyperlinked APIs</a>
|
||||
<a href="#tutorial-5-relationships-hyperlinked-apis">Tutorial 5: Relationships & Hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
|
|
@ -346,7 +346,7 @@
|
|||
|
||||
|
||||
<li class="main">
|
||||
<a href="#tutorial-6-viewsets-routers">Tutorial 6: ViewSets Routers</a>
|
||||
<a href="#tutorial-6-viewsets-routers">Tutorial 6: ViewSets & Routers</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
|
|
@ -496,7 +496,7 @@ REST_FRAMEWORK = {
|
|||
<hr />
|
||||
<h2 id="testing-our-api"><a class="toclink" href="#testing-our-api">Testing our API</a></h2>
|
||||
<p>We're now ready to test the API we've built. Let's fire up the server from the command line.</p>
|
||||
<pre><code>python ./manage.py runserver
|
||||
<pre><code>python manage.py runserver
|
||||
</code></pre>
|
||||
<p>We can now access our API, both from the command-line, using tools like <code>curl</code>...</p>
|
||||
<pre><code>bash: curl -H 'Accept: application/json; indent=4' -u admin:password123 http://127.0.0.1:8000/users/
|
||||
|
@ -545,7 +545,7 @@ HTTP/1.1 200 OK
|
|||
]
|
||||
}
|
||||
</code></pre>
|
||||
<p>Or directly through the browser...</p>
|
||||
<p>Or directly through the browser, by going to the URL <code>http://127.0.0.1:8000/users/</code>...</p>
|
||||
<p><img alt="Quick start image" src="../../img/quickstart.png" /></p>
|
||||
<p>If you're working through the browser, make sure to login using the control in the top right corner.</p>
|
||||
<p>Great, that was easy!</p>
|
||||
|
|
Loading…
Reference in New Issue
Block a user