mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-04-19 00:22:09 +03:00
Deployed 47cfbdac
with MkDocs version: 1.1
This commit is contained in:
parent
7d6adcd0fa
commit
b3f7747027
|
@ -442,7 +442,7 @@ provided in Django.</p>
|
|||
decorators with class based views. This can be used with
|
||||
other cache decorators such as <a href="https://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache"><code>cache_page</code></a> and
|
||||
<a href="https://docs.djangoproject.com/en/dev/topics/http/decorators/#django.views.decorators.vary.vary_on_cookie"><code>vary_on_cookie</code></a>.</p>
|
||||
<pre><code class="python">from django.utils.decorators import method_decorator
|
||||
<pre><code class="language-python">from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.decorators.vary import vary_on_cookie
|
||||
|
||||
|
@ -474,7 +474,6 @@ class PostView(APIView):
|
|||
}
|
||||
return Response(content)
|
||||
</code></pre>
|
||||
|
||||
<p><strong>NOTE:</strong> The <a href="https://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache"><code>cache_page</code></a> decorator only caches the
|
||||
<code>GET</code> and <code>HEAD</code> responses with status 200.</p>
|
||||
|
||||
|
|
|
@ -818,7 +818,7 @@ True
|
|||
you can implement a completely custom relational field, that describes exactly how the
|
||||
output representation should be generated from the model instance.</p>
|
||||
<p>To implement a custom relational field, you should override <code>RelatedField</code>, and implement the <code>.to_representation(self, value)</code> method. This method takes the target of the field as the <code>value</code> argument, and should return the representation that should be used to serialize the target. The <code>value</code> argument will typically be a model instance.</p>
|
||||
<p>If you want to implement a read-write relational field, you must also implement the <code>.to_internal_value(self, data)</code> method.</p>
|
||||
<p>If you want to implement a read-write relational field, you must also implement the <a href="https://www.django-rest-framework.org/api-guide/serializers/#to_internal_valueself-data"><code>.to_internal_value(self, data)</code> method</a>.</p>
|
||||
<p>To provide a dynamic queryset based on the <code>context</code>, you can also override <code>.get_queryset(self)</code> instead of specifying <code>.queryset</code> on the class or when initializing the field.</p>
|
||||
<h2 id="example_1"><a class="toclink" href="#example_1">Example</a></h2>
|
||||
<p>For example, we could define a relational field to serialize a track to a custom string representation, using its ordering, title, and duration:</p>
|
||||
|
|
|
@ -483,9 +483,8 @@ can interact with your API.</p>
|
|||
</ul>
|
||||
<h3 id="generating-a-static-schema-with-the-generateschema-management-command"><a class="toclink" href="#generating-a-static-schema-with-the-generateschema-management-command">Generating a static schema with the <code>generateschema</code> management command</a></h3>
|
||||
<p>If your schema is static, you can use the <code>generateschema</code> management command:</p>
|
||||
<pre><code class="bash">./manage.py generateschema --file openapi-schema.yml
|
||||
<pre><code class="language-bash">./manage.py generateschema --file openapi-schema.yml
|
||||
</code></pre>
|
||||
|
||||
<p>Once you've generated a schema in this way you can annotate it with any
|
||||
additional information that cannot be automatically inferred by the schema
|
||||
generator.</p>
|
||||
|
@ -497,7 +496,7 @@ values, for example, you can route a <code>SchemaView</code> that will generate
|
|||
your schema on demand.</p>
|
||||
<p>To route a <code>SchemaView</code>, use the <code>get_schema_view()</code> helper.</p>
|
||||
<p>In <code>urls.py</code>:</p>
|
||||
<pre><code class="python">from rest_framework.schemas import get_schema_view
|
||||
<pre><code class="language-python">from rest_framework.schemas import get_schema_view
|
||||
|
||||
urlpatterns = [
|
||||
# ...
|
||||
|
@ -512,7 +511,6 @@ urlpatterns = [
|
|||
# ...
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<h4 id="get_schema_view"><a class="toclink" href="#get_schema_view"><code>get_schema_view()</code></a></h4>
|
||||
<p>The <code>get_schema_view()</code> helper takes the following keyword arguments:</p>
|
||||
<ul>
|
||||
|
@ -567,9 +565,8 @@ schema_view = get_schema_view(
|
|||
</ul>
|
||||
<h2 id="schemagenerator"><a class="toclink" href="#schemagenerator">SchemaGenerator</a></h2>
|
||||
<p><strong>Schema-level customization</strong></p>
|
||||
<pre><code class="python">from rest_framework.schemas.openapi import SchemaGenerator
|
||||
<pre><code class="language-python">from rest_framework.schemas.openapi import SchemaGenerator
|
||||
</code></pre>
|
||||
|
||||
<p><code>SchemaGenerator</code> is a class that walks a list of routed URL patterns, requests
|
||||
the schema for each view and collates the resulting OpenAPI schema.</p>
|
||||
<p>Typically you won't need to instantiate <code>SchemaGenerator</code> yourself, but you can
|
||||
|
@ -600,17 +597,15 @@ per-user permissions to the resulting schema generation.</p>
|
|||
dictionary For example you might wish to add terms of service to the <a href="https://swagger.io/specification/#infoObject">top-level
|
||||
<code>info</code> object</a>:</p>
|
||||
<pre><code>class TOSSchemaGenerator(SchemaGenerator):
|
||||
def get_schema(self):
|
||||
schema = super().get_schema()
|
||||
def get_schema(self, *args, **kwargs):
|
||||
schema = super().get_schema(*args, **kwargs)
|
||||
schema["info"]["termsOfService"] = "https://example.com/tos.html"
|
||||
return schema
|
||||
</code></pre>
|
||||
|
||||
<h2 id="autoschema"><a class="toclink" href="#autoschema">AutoSchema</a></h2>
|
||||
<p><strong>Per-View Customization</strong></p>
|
||||
<pre><code class="python">from rest_framework.schemas.openapi import AutoSchema
|
||||
<pre><code class="language-python">from rest_framework.schemas.openapi import AutoSchema
|
||||
</code></pre>
|
||||
|
||||
<p>By default, view introspection is performed by an <code>AutoSchema</code> instance
|
||||
accessible via the <code>schema</code> attribute on <code>APIView</code>.</p>
|
||||
<pre><code>auto_schema = some_view.schema
|
||||
|
@ -624,10 +619,9 @@ and path:</p>
|
|||
the endpoint, including path and query parameters for pagination, filtering,
|
||||
and so on.</li>
|
||||
</ul>
|
||||
<pre><code class="python">components = auto_schema.get_components(...)
|
||||
<pre><code class="language-python">components = auto_schema.get_components(...)
|
||||
operation = auto_schema.get_operation(...)
|
||||
</code></pre>
|
||||
|
||||
<p>In compiling the schema, <code>SchemaGenerator</code> calls <code>get_components()</code> and
|
||||
<code>get_operation()</code> for each view, allowed method, and path.</p>
|
||||
<hr />
|
||||
|
@ -644,7 +638,7 @@ field APIs.</p>
|
|||
<p>Keeping with this pattern, try not to let schema logic leak into your own
|
||||
views, serializers, or fields when customizing the schema generation. You might
|
||||
be tempted to do something like this:</p>
|
||||
<pre><code class="python">class CustomSchema(AutoSchema):
|
||||
<pre><code class="language-python">class CustomSchema(AutoSchema):
|
||||
"""
|
||||
AutoSchema subclass using schema_extra_info on the view.
|
||||
"""
|
||||
|
@ -654,13 +648,12 @@ class CustomView(APIView):
|
|||
schema = CustomSchema()
|
||||
schema_extra_info = ... some extra info ...
|
||||
</code></pre>
|
||||
|
||||
<p>Here, the <code>AutoSchema</code> subclass goes looking for <code>schema_extra_info</code> on the
|
||||
view. This is <em>OK</em> (it doesn't actually hurt) but it means you'll end up with
|
||||
your schema logic spread out in a number of different places.</p>
|
||||
<p>Instead try to subclass <code>AutoSchema</code> such that the <code>extra_info</code> doesn't leak
|
||||
out into the view:</p>
|
||||
<pre><code class="python">class BaseSchema(AutoSchema):
|
||||
<pre><code class="language-python">class BaseSchema(AutoSchema):
|
||||
"""
|
||||
AutoSchema subclass that knows how to use extra_info.
|
||||
"""
|
||||
|
@ -672,14 +665,13 @@ class CustomSchema(BaseSchema):
|
|||
class CustomView(APIView):
|
||||
schema = CustomSchema()
|
||||
</code></pre>
|
||||
|
||||
<p>This style is slightly more verbose but maintains the encapsulation of the
|
||||
schema related code. It's more <em>cohesive</em> in the <em>parlance</em>. It'll keep the
|
||||
rest of your API code more tidy.</p>
|
||||
<p>If an option applies to many view classes, rather than creating a specific
|
||||
subclass per-view, you may find it more convenient to allow specifying the
|
||||
option as an <code>__init__()</code> kwarg to your base <code>AutoSchema</code> subclass:</p>
|
||||
<pre><code class="python">class CustomSchema(BaseSchema):
|
||||
<pre><code class="language-python">class CustomSchema(BaseSchema):
|
||||
def __init__(self, **kwargs):
|
||||
# store extra_info for later
|
||||
self.extra_info = kwargs.pop("extra_info")
|
||||
|
@ -690,7 +682,6 @@ class CustomView(APIView):
|
|||
extra_info=... some extra info ...
|
||||
)
|
||||
</code></pre>
|
||||
|
||||
<p>This saves you having to create a custom subclass per-view for a commonly used option.</p>
|
||||
<p>Not all <code>AutoSchema</code> methods expose related <code>__init__()</code> kwargs, but those for
|
||||
the more commonly needed options do.</p>
|
||||
|
@ -714,7 +705,7 @@ serializer-level fields.</p>
|
|||
<p>Maps individual serializer fields to their schema representation. The base implementation
|
||||
will handle the default fields that Django REST Framework provides.</p>
|
||||
<p>For <code>SerializerMethodField</code> instances, for which the schema is unknown, or custom field subclasses you should override <code>map_field()</code> to generate the correct schema:</p>
|
||||
<pre><code class="python">class CustomSchema(AutoSchema):
|
||||
<pre><code class="language-python">class CustomSchema(AutoSchema):
|
||||
"""Extension of ``AutoSchema`` to add support for custom field schemas."""
|
||||
|
||||
def map_field(self, field):
|
||||
|
@ -722,7 +713,6 @@ will handle the default fields that Django REST Framework provides.</p>
|
|||
# ...
|
||||
return super().map_field(field)
|
||||
</code></pre>
|
||||
|
||||
<p>Authors of third-party packages should aim to provide an <code>AutoSchema</code> subclass,
|
||||
and a mixin, overriding <code>map_field()</code> so that users can easily generate schemas
|
||||
for their custom fields.</p>
|
||||
|
@ -766,7 +756,6 @@ common customizations, if the default generated values are not appropriate.</p>
|
|||
)
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<p>Assuming a <code>Pet</code> model and <code>PetSerializer</code> serializer, the kwargs in this
|
||||
example are probably not needed. Often, though, you'll need to pass the kwargs
|
||||
if you have multiple view targeting the same model, or have multiple views with
|
||||
|
|
|
@ -844,7 +844,7 @@ class GameRecord(serializers.Serializer):
|
|||
<p>For more information see the <a href="../validators/">validators documentation</a>.</p>
|
||||
<h2 id="accessing-the-initial-data-and-instance"><a class="toclink" href="#accessing-the-initial-data-and-instance">Accessing the initial data and instance</a></h2>
|
||||
<p>When passing an initial object or queryset to a serializer instance, the object will be made available as <code>.instance</code>. If no initial object is passed then the <code>.instance</code> attribute will be <code>None</code>.</p>
|
||||
<p>When passing data to a serializer instance, the unmodified data will be made available as <code>.initial_data</code>. If the data keyword argument is not passed then the <code>.initial_data</code> attribute will not exist.</p>
|
||||
<p>When passing data to a serializer instance, the unmodified data will be made available as <code>.initial_data</code>. If the <code>data</code> keyword argument is not passed then the <code>.initial_data</code> attribute will not exist.</p>
|
||||
<h2 id="partial-updates"><a class="toclink" href="#partial-updates">Partial updates</a></h2>
|
||||
<p>By default, serializers must be passed values for all required fields or they will raise validation errors. You can use the <code>partial</code> argument in order to allow partial updates.</p>
|
||||
<pre><code># Update `comment` with partial data
|
||||
|
|
|
@ -577,7 +577,7 @@ def hello_world(request):
|
|||
from rest_framework.throttling import UserRateThrottle
|
||||
|
||||
class OncePerDayUserThrottle(UserRateThrottle):
|
||||
rate = '1/day'
|
||||
rate = '1/day'
|
||||
|
||||
@api_view(['GET'])
|
||||
@throttle_classes([OncePerDayUserThrottle])
|
||||
|
|
|
@ -630,21 +630,21 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
serializer = self.get_serializer(recent_users, many=True)
|
||||
return Response(serializer.data)
|
||||
</code></pre>
|
||||
<p>The decorator can additionally take extra arguments that will be set for the routed view only. For example:</p>
|
||||
<pre><code> @action(detail=True, methods=['post'], permission_classes=[IsAdminOrIsSelf])
|
||||
def set_password(self, request, pk=None):
|
||||
...
|
||||
</code></pre>
|
||||
<p>The <code>action</code> decorator will route <code>GET</code> requests by default, but may also accept other HTTP methods by setting the <code>methods</code> argument. For example:</p>
|
||||
<pre><code> @action(detail=True, methods=['post', 'delete'])
|
||||
def unset_password(self, request, pk=None):
|
||||
...
|
||||
</code></pre>
|
||||
<p>The two new actions will then be available at the urls <code>^users/{pk}/set_password/$</code> and <code>^users/{pk}/unset_password/$</code></p>
|
||||
<p>The decorator allows you to override any viewset-level configuration such as <code>permission_classes</code>, <code>serializer_class</code>, <code>filter_backends</code>...:</p>
|
||||
<pre><code> @action(detail=True, methods=['post'], permission_classes=[IsAdminOrIsSelf])
|
||||
def set_password(self, request, pk=None):
|
||||
...
|
||||
</code></pre>
|
||||
<p>The two new actions will then be available at the urls <code>^users/{pk}/set_password/$</code> and <code>^users/{pk}/unset_password/$</code>. Use the <code>url_path</code> and <code>url_name</code> parameters to change the URL segement and the reverse URL name of the action.</p>
|
||||
<p>To view all extra actions, call the <code>.get_extra_actions()</code> method.</p>
|
||||
<h3 id="routing-additional-http-methods-for-extra-actions"><a class="toclink" href="#routing-additional-http-methods-for-extra-actions">Routing additional HTTP methods for extra actions</a></h3>
|
||||
<p>Extra actions can map additional HTTP methods to separate <code>ViewSet</code> methods. For example, the above password set/unset methods could be consolidated into a single route. Note that additional mappings do not accept arguments.</p>
|
||||
<pre><code class="python"> @action(detail=True, methods=['put'], name='Change Password')
|
||||
<pre><code class="language-python"> @action(detail=True, methods=['put'], name='Change Password')
|
||||
def password(self, request, pk=None):
|
||||
"""Update the user's password."""
|
||||
...
|
||||
|
@ -654,20 +654,17 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
"""Delete the user's password."""
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<h2 id="reversing-action-urls"><a class="toclink" href="#reversing-action-urls">Reversing action URLs</a></h2>
|
||||
<p>If you need to get the URL of an action, use the <code>.reverse_action()</code> method. This is a convenience wrapper for <code>reverse()</code>, automatically passing the view's <code>request</code> object and prepending the <code>url_name</code> with the <code>.basename</code> attribute.</p>
|
||||
<p>Note that the <code>basename</code> is provided by the router during <code>ViewSet</code> registration. If you are not using a router, then you must provide the <code>basename</code> argument to the <code>.as_view()</code> method.</p>
|
||||
<p>Using the example from the previous section:</p>
|
||||
<pre><code class="python">>>> view.reverse_action('set-password', args=['1'])
|
||||
<pre><code class="language-python">>>> view.reverse_action('set-password', args=['1'])
|
||||
'http://localhost:8000/api/users/1/set_password'
|
||||
</code></pre>
|
||||
|
||||
<p>Alternatively, you can use the <code>url_name</code> attribute set by the <code>@action</code> decorator.</p>
|
||||
<pre><code class="python">>>> view.reverse_action(view.set_password.url_name, args=['1'])
|
||||
<pre><code class="language-python">>>> view.reverse_action(view.set_password.url_name, args=['1'])
|
||||
'http://localhost:8000/api/users/1/set_password'
|
||||
</code></pre>
|
||||
|
||||
<p>The <code>url_name</code> argument for <code>.reverse_action()</code> should match the same argument to the <code>@action</code> decorator. Additionally, this method can be used to reverse the default actions, such as <code>list</code> and <code>create</code>.</p>
|
||||
<hr />
|
||||
<h1 id="api-reference"><a class="toclink" href="#api-reference">API Reference</a></h1>
|
||||
|
|
|
@ -477,12 +477,11 @@
|
|||
<p>If you're currently using the CoreAPI schemas, you'll need to make sure to
|
||||
update your REST framework settings to include <code>DEFAULT_SCHEMA_CLASS</code> explicitly.</p>
|
||||
<p><strong>settings.py</strong>:</p>
|
||||
<pre><code class="python">REST_FRAMEWORK = {
|
||||
<pre><code class="language-python">REST_FRAMEWORK = {
|
||||
...
|
||||
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema'
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>You'll still be able to keep using CoreAPI schemas, API docs, and client for the
|
||||
foreseeable future. We'll aim to ensure that the CoreAPI schema generator remains
|
||||
available as a third party package, even once it has eventually been removed
|
||||
|
@ -496,7 +495,7 @@ command.</p>
|
|||
<p>Alternately, to have the project serve an API schema, use the <code>get_schema_view()</code>
|
||||
shortcut.</p>
|
||||
<p>In your <code>urls.py</code>:</p>
|
||||
<pre><code class="python">from rest_framework.schemas import get_schema_view
|
||||
<pre><code class="language-python">from rest_framework.schemas import get_schema_view
|
||||
|
||||
urlpatterns = [
|
||||
# ...
|
||||
|
@ -510,7 +509,6 @@ urlpatterns = [
|
|||
# ...
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<h3 id="customization"><a class="toclink" href="#customization">Customization</a></h3>
|
||||
<p>For customizations that you want to apply across the entire API, you can subclass <code>rest_framework.schemas.openapi.SchemaGenerator</code> and provide it as an argument
|
||||
to the <code>generateschema</code> command or <code>get_schema_view()</code> helper function.</p>
|
||||
|
@ -552,7 +550,6 @@ continued development by <strong><a href="../funding/">signing up for a paid pla
|
|||
<li><a href="https://hubs.ly/H0f30Lf0" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/kloudless-plus-text.png)">Kloudless</a></li>
|
||||
<li><a href="https://lightsonsoftware.com" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/lightson-dark.png)">Lights On Software</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">wonderful sponsors</a>, and in particular to our premium backers, <a href="https://getsentry.com/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, <a href="https://software.esg-usa.com/">ESG</a>, <a href="https://rollbar.com/?utm_source=django&utm_medium=sponsorship&utm_campaign=freetrial">Rollbar</a>, <a href="https://cadre.com">Cadre</a>, <a href="https://hubs.ly/H0f30Lf0">Kloudless</a>, and <a href="https://lightsonsoftware.com">Lights On Software</a>.</em></p>
|
||||
|
|
|
@ -475,7 +475,7 @@ include:</p>
|
|||
</ul>
|
||||
<p>In this example view operation descriptions for the <code>get</code> and <code>post</code> methods will
|
||||
be extracted from the class docstring:</p>
|
||||
<pre><code class="python">class DocStringExampleListView(APIView):
|
||||
<pre><code class="language-python">class DocStringExampleListView(APIView):
|
||||
"""
|
||||
get: A description of my GET operation.
|
||||
post: A description of my POST operation.
|
||||
|
@ -488,7 +488,6 @@ post: A description of my POST operation.
|
|||
def post(self, request, *args, **kwargs):
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<h2 id="validator-default-context"><a class="toclink" href="#validator-default-context">Validator / Default Context</a></h2>
|
||||
<p>In some circumstances a Validator class or a Default class may need to access the serializer field with which it is called, or the <code>.context</code> with which the serializer was instantiated. In particular:</p>
|
||||
<ul>
|
||||
|
@ -499,21 +498,19 @@ post: A description of my POST operation.
|
|||
<p>Instead, validators or defaults which require the serializer context, should include a <code>requires_context = True</code> attribute on the class.</p>
|
||||
<p>The <code>__call__</code> method should then include an additional <code>serializer_field</code> argument.</p>
|
||||
<p>Validator implementations will look like this:</p>
|
||||
<pre><code class="python">class CustomValidator:
|
||||
<pre><code class="language-python">class CustomValidator:
|
||||
requires_context = True
|
||||
|
||||
def __call__(self, value, serializer_field):
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<p>Default implementations will look like this:</p>
|
||||
<pre><code class="python">class CustomDefault:
|
||||
<pre><code class="language-python">class CustomDefault:
|
||||
requires_context = True
|
||||
|
||||
def __call__(self, serializer_field):
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h2 id="funding"><a class="toclink" href="#funding">Funding</a></h2>
|
||||
<p>REST framework is a <em>collaboratively funded project</em>. If you use
|
||||
|
@ -530,7 +527,6 @@ continued development by <strong><a href="../funding/">signing up for a paid pla
|
|||
<li><a href="https://lightsonsoftware.com" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/lightson-dark.png)">Lights On Software</a></li>
|
||||
<li><a href="https://retool.com/?utm_source=djangorest&utm_medium=sponsorship" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/retool-sidebar.png)">Retool</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">wonderful sponsors</a>, and in particular to our premium backers, <a href="https://getsentry.com/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, <a href="https://software.esg-usa.com/">ESG</a>, <a href="https://rollbar.com/?utm_source=django&utm_medium=sponsorship&utm_campaign=freetrial">Rollbar</a>, <a href="https://cadre.com">Cadre</a>, <a href="https://hubs.ly/H0f30Lf0">Kloudless</a>, <a href="https://lightsonsoftware.com">Lights On Software</a>, and <a href="https://retool.com/?utm_source=djangorest&utm_medium=sponsorship">Retool</a>.</em></p>
|
||||
|
|
|
@ -511,11 +511,10 @@ in the URL path.</p>
|
|||
</tbody>
|
||||
</table>
|
||||
<p>The tags used for a particular view may also be overridden...</p>
|
||||
<pre><code class="python">class MyOrders(APIView):
|
||||
<pre><code class="language-python">class MyOrders(APIView):
|
||||
schema = AutoSchema(tags=['users', 'orders'])
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<p>See <a href="https://www.django-rest-framework.org/api-guide/schemas/#grouping-operations-with-tags">the schema documentation</a> for more information.</p>
|
||||
<h2 id="customizing-the-operation-id"><a class="toclink" href="#customizing-the-operation-id">Customizing the operation ID.</a></h2>
|
||||
<p>REST framework automatically determines operation IDs to use in OpenAPI
|
||||
|
@ -529,10 +528,9 @@ and response objects. This is in contrast with the previous approach, which
|
|||
fully expanded the request and response bodies for each operation.</p>
|
||||
<p>The names used for a component default to using the serializer class name, <a href="https://www.django-rest-framework.org/api-guide/schemas/#components">but
|
||||
may be overridden if needed</a>...</p>
|
||||
<pre><code class="python">class MyOrders(APIView):
|
||||
<pre><code class="language-python">class MyOrders(APIView):
|
||||
schema = AutoSchema(component_name="OrderDetails")
|
||||
</code></pre>
|
||||
|
||||
<h2 id="more-public-api"><a class="toclink" href="#more-public-api">More Public API</a></h2>
|
||||
<p>Many methods on the <code>AutoSchema</code> class have now been promoted to public API,
|
||||
allowing you to more fully customize the schema generation. The following methods
|
||||
|
@ -564,7 +562,7 @@ classes will correctly map the model field.</p>
|
|||
<p>The class now supports nested search within <code>JSONField</code> and <code>HStoreField</code>, using
|
||||
the double underscore notation for traversing which element of the field the
|
||||
search should apply to.</p>
|
||||
<pre><code class="python">class SitesSearchView(generics.ListAPIView):
|
||||
<pre><code class="language-python">class SitesSearchView(generics.ListAPIView):
|
||||
"""
|
||||
An API view to return a list of archaeological sites, optionally filtered
|
||||
by a search against the site name or location. (Location searches are
|
||||
|
@ -575,11 +573,10 @@ search should apply to.</p>
|
|||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['site_name', 'location__region', 'location__country']
|
||||
</code></pre>
|
||||
|
||||
<h3 id="searches-against-annotate-fields"><a class="toclink" href="#searches-against-annotate-fields">Searches against annotate fields</a></h3>
|
||||
<p>Django allows querysets to create additional virtual fields, using the <code>.annotate</code>
|
||||
method. We now support searching against annotate fields.</p>
|
||||
<pre><code class="python">class PublisherSearchView(generics.ListAPIView):
|
||||
<pre><code class="language-python">class PublisherSearchView(generics.ListAPIView):
|
||||
"""
|
||||
Search for publishers, optionally filtering the search against the average
|
||||
rating of all their books.
|
||||
|
@ -589,7 +586,6 @@ method. We now support searching against annotate fields.</p>
|
|||
filter_backends = [filters.SearchFilter]
|
||||
search_fields = ['avg_rating']
|
||||
</code></pre>
|
||||
|
||||
<hr />
|
||||
<h2 id="funding"><a class="toclink" href="#funding">Funding</a></h2>
|
||||
<p>REST framework is a <em>collaboratively funded project</em>. If you use
|
||||
|
@ -606,7 +602,6 @@ continued development by <strong><a href="../funding/">signing up for a paid pla
|
|||
<li><a href="https://lightsonsoftware.com" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/lightson-dark.png)">Lights On Software</a></li>
|
||||
<li><a href="https://retool.com/?utm_source=djangorest&utm_medium=sponsorship" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/retool-sidebar.png)">Retool</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">wonderful sponsors</a>, and in particular to our premium backers, <a href="https://getsentry.com/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, <a href="https://software.esg-usa.com/">ESG</a>, <a href="https://rollbar.com/?utm_source=django&utm_medium=sponsorship&utm_campaign=freetrial">Rollbar</a>, <a href="https://cadre.com">Cadre</a>, <a href="https://hubs.ly/H0f30Lf0">Kloudless</a>, <a href="https://lightsonsoftware.com">Lights On Software</a>, and <a href="https://retool.com/?utm_source=djangorest&utm_medium=sponsorship">Retool</a>.</em></p>
|
||||
|
|
|
@ -480,7 +480,6 @@ Right now we're over 60% of the way towards achieving that.
|
|||
<li><a href="https://sentry.io/welcome/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/sentry130.png)">Sentry</a></li>
|
||||
<li><a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/stream-130.png)">Stream</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="https://www.rover.com/careers/">Rover</a>, <a href="https://sentry.io/welcome/">Sentry</a>, and <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>.</em></p>
|
||||
|
|
|
@ -494,7 +494,6 @@ we strongly encourage you to invest in its continued development by
|
|||
<li><a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/stream-130.png)">Stream</a></li>
|
||||
<li><a href="https://www.machinalis.com/#services" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/Machinalis130.png)">Machinalis</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">sponsors</a>, and in particular to our premium backers, <a href="https://www.rover.com/careers/">Rover</a>, <a href="https://sentry.io/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, and <a href="https://www.machinalis.com/#services">Machinalis</a>.</em></p>
|
||||
|
@ -516,7 +515,7 @@ you to <a href="../api-guide/schemas/#schemas-as-documentation">use the schema d
|
|||
<p>Include the schema view in your URL conf:</p>
|
||||
</li>
|
||||
</ul>
|
||||
<pre><code class="py">from rest_framework.schemas import get_schema_view
|
||||
<pre><code class="language-py">from rest_framework.schemas import get_schema_view
|
||||
from rest_framework_swagger.renderers import OpenAPIRenderer, SwaggerUIRenderer
|
||||
|
||||
schema_view = get_schema_view(
|
||||
|
@ -529,7 +528,6 @@ urlpatterns = [
|
|||
...
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<p>There have been a large number of fixes to the schema generation. These should
|
||||
resolve issues for anyone using the latest version of the <code>django-rest-swagger</code>
|
||||
package.</p>
|
||||
|
|
|
@ -489,7 +489,6 @@ we strongly encourage you to invest in its continued development by
|
|||
<li><a href="https://rollbar.com" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rollbar.png)">Rollbar</a></li>
|
||||
<li><a href="https://micropyramid.com/django-rest-framework-development-services/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/mp-text-logo.png)">MicroPyramid</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">sponsors</a>, and in particular to our premium backers, <a href="https://www.rover.com/careers/">Rover</a>, <a href="https://sentry.io/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, <a href="https://machinalis.com/">Machinalis</a>, <a href="https://rollbar.com">Rollbar</a>, and <a href="https://micropyramid.com/django-rest-framework-development-services/">MicroPyramid</a>.</em></p>
|
||||
|
|
|
@ -482,7 +482,6 @@
|
|||
<li><a href="https://machinalis.com/" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/Machinalis130.png)">Machinalis</a></li>
|
||||
<li><a href="https://rollbar.com" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/rollbar.png)">Rollbar</a></li>
|
||||
</ul>
|
||||
|
||||
<div style="clear: both; padding-bottom: 20px;"></div>
|
||||
|
||||
<p><em>As well as our release sponsor, we'd like to say thanks in particular our premium backers, <a href="https://www.rover.com/careers/">Rover</a>, <a href="https://sentry.io/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, <a href="https://machinalis.com/">Machinalis</a>, and <a href="https://rollbar.com">Rollbar</a>.</em></p>
|
||||
|
|
|
@ -491,7 +491,6 @@
|
|||
<li><a href="https://loadimpact.com/?utm_campaign=Sponsorship%20links&utm_source=drf&utm_medium=drf" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/load-impact.png)">Load Impact</a></li>
|
||||
<li><a href="https://hubs.ly/H0f30Lf0" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/kloudless.png)">Kloudless</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">wonderful sponsors</a>, and in particular to our premium backers, <a href="https://www.rover.com/careers/">Rover</a>, <a href="https://sentry.io/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, <a href="https://auklet.io/">Auklet</a>, <a href="https://rollbar.com">Rollbar</a>, <a href="https://cadre.com">Cadre</a>, <a href="https://loadimpact.com/?utm_campaign=Sponsorship%20links&utm_source=drf&utm_medium=drf">Load Impact</a>, and <a href="https://hubs.ly/H0f30Lf0">Kloudless</a>.</em></p>
|
||||
|
@ -507,7 +506,7 @@ option if it is selected via HTTP content negotiation.</li>
|
|||
the schema into your repository.</li>
|
||||
</ul>
|
||||
<p>Here's an example of adding an OpenAPI schema to the URL conf:</p>
|
||||
<pre><code class="python">from rest_framework.schemas import get_schema_view
|
||||
<pre><code class="language-python">from rest_framework.schemas import get_schema_view
|
||||
from rest_framework.renderers import JSONOpenAPIRenderer
|
||||
from django.urls import path
|
||||
|
||||
|
@ -522,32 +521,27 @@ urlpatterns = [
|
|||
...
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<p>And here's how you can use the <code>generateschema</code> management command:</p>
|
||||
<pre><code class="shell">$ python manage.py generateschema --format openapi > schema.yml
|
||||
<pre><code class="language-shell">$ python manage.py generateschema --format openapi > schema.yml
|
||||
</code></pre>
|
||||
|
||||
<p>There's lots of different tooling that you can use for working with OpenAPI
|
||||
schemas. One option that we're working on is the <a href="https://docs.apistar.com/">API Star</a>
|
||||
command line tool.</p>
|
||||
<p>You can use <code>apistar</code> to validate your API schema:</p>
|
||||
<pre><code class="shell">$ apistar validate --path schema.json --format openapi
|
||||
<pre><code class="language-shell">$ apistar validate --path schema.json --format openapi
|
||||
✓ Valid OpenAPI schema.
|
||||
</code></pre>
|
||||
|
||||
<p>Or to build API documentation:</p>
|
||||
<pre><code class="shell">$ apistar docs --path schema.json --format openapi
|
||||
<pre><code class="language-shell">$ apistar docs --path schema.json --format openapi
|
||||
✓ Documentation built at "build/index.html".
|
||||
</code></pre>
|
||||
|
||||
<p>API Star also includes a <a href="https://docs.apistar.com/client-library/">dynamic client library</a>
|
||||
that uses an API schema to automatically provide a client library interface for making requests.</p>
|
||||
<h2 id="composable-permission-classes"><a class="toclink" href="#composable-permission-classes">Composable permission classes</a></h2>
|
||||
<p>You can now compose permission classes using the and/or operators, <code>&</code> and <code>|</code>.</p>
|
||||
<p>For example...</p>
|
||||
<pre><code class="python">permission_classes = [IsAuthenticated & (ReadOnly | IsAdmin)]
|
||||
<pre><code class="language-python">permission_classes = [IsAuthenticated & (ReadOnly | IsAdmin)]
|
||||
</code></pre>
|
||||
|
||||
<p>If you're using custom permission classes then make sure that you are subclassing
|
||||
from <code>BasePermission</code> in order to enable this support.</p>
|
||||
<h2 id="viewset-extra-actions-available-in-the-browsable-api"><a class="toclink" href="#viewset-extra-actions-available-in-the-browsable-api">ViewSet <em>Extra Actions</em> available in the Browsable API</a></h2>
|
||||
|
|
|
@ -650,7 +650,6 @@ DRF is one of the core reasons why Django is top choice among web frameworks tod
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div style="clear: both; padding-top: 50px"></div>
|
||||
|
||||
<p><em>Billing is monthly and you can cancel at any time.</em></p>
|
||||
|
@ -776,12 +775,11 @@ DRF is one of the core reasons why Django is top choice among web frameworks tod
|
|||
<h2 id="accountability"><a class="toclink" href="#accountability">Accountability</a></h2>
|
||||
<p>In an effort to keep the project as transparent as possible, we are releasing <a href="https://www.encode.io/reports/march-2018/">monthly progress reports</a> and regularly include financial reports and cost breakdowns.</p>
|
||||
<!-- Begin MailChimp Signup Form -->
|
||||
|
||||
<p><link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
|
||||
<p><link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css"></p>
|
||||
<style type="text/css">
|
||||
#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
|
||||
/<em> Add your own MailChimp form style overrides in your site stylesheet or in this style block.
|
||||
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. </em>/
|
||||
/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
|
||||
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
|
||||
</style>
|
||||
<div id="mc_embed_signup">
|
||||
<form action="//encode.us13.list-manage.com/subscribe/post?u=b6b66bb5e4c7cb484a85c8dd7&id=e382ef68ef" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
|
||||
|
@ -800,8 +798,10 @@ DRF is one of the core reasons why Django is top choice among web frameworks tod
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
|
||||
<!--End mc_embed_signup--></p>
|
||||
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script>
|
||||
<script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
|
||||
<!--End mc_embed_signup-->
|
||||
|
||||
<hr />
|
||||
<h2 id="frequently-asked-questions"><a class="toclink" href="#frequently-asked-questions">Frequently asked questions</a></h2>
|
||||
<p><strong>Q: Can you issue monthly invoices?</strong>
|
||||
|
|
|
@ -468,12 +468,11 @@ act as the business entity behind REST framework. I will be issuing monthly repo
|
|||
from Encode on progress both towards the Mozilla grant, and for development time
|
||||
funded via the <a href="../funding/">REST framework paid plans</a>.</p>
|
||||
<!-- Begin MailChimp Signup Form -->
|
||||
|
||||
<p><link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css">
|
||||
<p><link href="//cdn-images.mailchimp.com/embedcode/classic-10_7.css" rel="stylesheet" type="text/css"></p>
|
||||
<style type="text/css">
|
||||
#mc_embed_signup{background:#fff; clear:left; font:14px Helvetica,Arial,sans-serif; }
|
||||
/<em> Add your own MailChimp form style overrides in your site stylesheet or in this style block.
|
||||
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. </em>/
|
||||
/* Add your own MailChimp form style overrides in your site stylesheet or in this style block.
|
||||
We recommend moving this block and the preceding CSS link to the HEAD of your HTML file. */
|
||||
</style>
|
||||
<div id="mc_embed_signup">
|
||||
<form action="//encode.us13.list-manage.com/subscribe/post?u=b6b66bb5e4c7cb484a85c8dd7&id=e382ef68ef" method="post" id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" class="validate" target="_blank" novalidate>
|
||||
|
@ -492,8 +491,9 @@ funded via the <a href="../funding/">REST framework paid plans</a>.</p>
|
|||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script><script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
|
||||
<!--End mc_embed_signup--></p>
|
||||
<script type='text/javascript' src='//s3.amazonaws.com/downloads.mailchimp.com/js/mc-validate.js'></script>
|
||||
<script type='text/javascript'>(function($) {window.fnames = new Array(); window.ftypes = new Array();fnames[0]='EMAIL';ftypes[0]='email';fnames[1]='FNAME';ftypes[1]='text';fnames[2]='LNAME';ftypes[2]='text';}(jQuery));var $mcj = jQuery.noConflict(true);</script>
|
||||
<!--End mc_embed_signup-->
|
||||
|
||||
|
||||
</div> <!--/span-->
|
||||
|
|
|
@ -517,6 +517,13 @@
|
|||
</code></pre>
|
||||
<hr />
|
||||
<h2 id="312x-series"><a class="toclink" href="#312x-series">3.12.x series</a></h2>
|
||||
<h3 id="3122"><a class="toclink" href="#3122">3.12.2</a></h3>
|
||||
<p>Date: 13th October 2020</p>
|
||||
<ul>
|
||||
<li>Fix issue if <code>rest_framework.authtoken.models</code> is imported, but <code>rest_framework.authtoken</code> is not in INSTALLED_APPS. [#7571]</li>
|
||||
<li>Ignore subclasses of BrowsableAPIRenderer in OpenAPI schema. [#7497]</li>
|
||||
<li>Narrower exception catching in serilizer fields, to ensure that any errors in broken <code>get_queryset()</code> methods are not masked. [#7480]</li>
|
||||
</ul>
|
||||
<h3 id="3121"><a class="toclink" href="#3121">3.12.1</a></h3>
|
||||
<p>Date: 28th September 2020</p>
|
||||
<ul>
|
||||
|
@ -1634,53 +1641,30 @@ Previously may have been stored internally as <code>None</code>.</p>
|
|||
<hr />
|
||||
<p>For older release notes, <a href="https://github.com/encode/django-rest-framework/blob/version-2.4.x/docs/topics/release-notes.md">please see the version 2.x documentation</a>.</p>
|
||||
<!-- 3.0.1 -->
|
||||
|
||||
<!-- 3.0.2 -->
|
||||
|
||||
<!-- 3.0.3 -->
|
||||
|
||||
<!-- 3.0.4 -->
|
||||
|
||||
<!-- 3.0.5 -->
|
||||
|
||||
<!-- 3.1.1 -->
|
||||
|
||||
<!-- 3.1.2 -->
|
||||
|
||||
<!-- 3.1.3 -->
|
||||
|
||||
<!-- 3.2.0 -->
|
||||
|
||||
<!-- 3.2.1 -->
|
||||
|
||||
<!-- 3.2.2 -->
|
||||
|
||||
<!-- 3.2.3 -->
|
||||
|
||||
<!-- 3.2.4 -->
|
||||
|
||||
<!-- 3.2.5 -->
|
||||
|
||||
<!-- 3.3.0 -->
|
||||
|
||||
<!-- 3.3.1 -->
|
||||
|
||||
<!-- 3.3.2 -->
|
||||
|
||||
<!-- 3.3.3 -->
|
||||
|
||||
<!-- 3.4.0 -->
|
||||
|
||||
<!-- 3.4.1 -->
|
||||
|
||||
<!-- 3.4.2 -->
|
||||
|
||||
<!-- 3.4.3 -->
|
||||
|
||||
<!-- 3.4.4 -->
|
||||
|
||||
<!-- 3.4.5 -->
|
||||
|
||||
<!-- 3.4.6 -->
|
||||
|
||||
<!-- 3.4.7 -->
|
||||
|
@ -1694,41 +1678,23 @@ Previously may have been stored internally as <code>None</code>.</p>
|
|||
<!-- 3.5.4 -->
|
||||
|
||||
<!-- 3.6.1 -->
|
||||
|
||||
<!-- 3.6.2 -->
|
||||
|
||||
<!-- 3.6.3 -->
|
||||
|
||||
<!-- 3.6.4 -->
|
||||
|
||||
<!-- 3.7.0 -->
|
||||
|
||||
<!-- 3.7.1 -->
|
||||
|
||||
<!-- 3.7.2 -->
|
||||
|
||||
<!-- 3.7.3 -->
|
||||
|
||||
<!-- 3.7.4 -->
|
||||
|
||||
<!-- 3.7.5 -->
|
||||
|
||||
<!-- 3.8.0 -->
|
||||
|
||||
<!-- 3.8.1 -->
|
||||
|
||||
<!-- 3.8.2 -->
|
||||
|
||||
<!-- 3.9.0 -->
|
||||
|
||||
<!-- 3.9.1 -->
|
||||
|
||||
<!-- 3.9.2 -->
|
||||
|
||||
<!-- 3.9.3 -->
|
||||
|
||||
<!-- 3.10.0 -->
|
||||
|
||||
<!-- 3.11.0 -->
|
||||
|
||||
|
||||
|
|
|
@ -501,12 +501,12 @@
|
|||
<ul>
|
||||
<li><a href="https://www.dabapps.com/blog/api-performance-profiling-django-rest-framework/">Web API performance: Profiling Django REST Framework</a></li>
|
||||
<li><a href="https://bnotions.com/api-development-with-django-and-django-rest-framework/">API Development with Django and Django REST Framework</a></li>
|
||||
<li><a href="https://machinalis.com/blog/pandas-django-rest-framework-bokeh/">Integrating Pandas, Django REST Framework and Bokeh</a></li>
|
||||
<li><a href="https://machinalis.com/blog/controlling-uncertainty-on-web-applications-and-apis/">Controlling Uncertainty on Web Applications and APIs</a></li>
|
||||
<li><a href="https://machinalis.com/blog/full-text-search-on-django-rest-framework/">Full Text Search in Django REST Framework with Database Backends</a></li>
|
||||
<li><a href="https://machinalis.com/blog/oauth2-authentication/">OAuth2 Authentication with Django REST Framework and Custom Third-Party OAuth2 Backends</a></li>
|
||||
<li><a href="https://machinalis.com/blog/nested-resources-with-django/">Nested Resources with Django REST Framework</a></li>
|
||||
<li><a href="https://machinalis.com/blog/image-fields-with-django-rest-framework/">Image Fields with Django REST Framework</a></li>
|
||||
<li><a href="https://web.archive.org/web/20180104205117/http://machinalis.com/blog/pandas-django-rest-framework-bokeh/">Integrating Pandas, Django REST Framework and Bokeh</a></li>
|
||||
<li><a href="https://web.archive.org/web/20180104205043/https://machinalis.com/blog/controlling-uncertainty-on-web-applications-and-apis/">Controlling Uncertainty on Web Applications and APIs</a></li>
|
||||
<li><a href="https://web.archive.org/web/20180104205059/http://machinalis.com/blog/full-text-search-on-django-rest-framework/">Full Text Search in Django REST Framework with Database Backends</a></li>
|
||||
<li><a href="https://web.archive.org/web/20180104205054/http://machinalis.com/blog/oauth2-authentication/">OAuth2 Authentication with Django REST Framework and Custom Third-Party OAuth2 Backends</a></li>
|
||||
<li><a href="https://web.archive.org/web/20180104205109/http://machinalis.com/blog/nested-resources-with-django/">Nested Resources with Django REST Framework</a></li>
|
||||
<li><a href="https://web.archive.org/web/20180104205048/http://machinalis.com/blog/image-fields-with-django-rest-framework/">Image Fields with Django REST Framework</a></li>
|
||||
<li><a href="https://chatbotslife.com/chatbot-using-django-rest-framework-api-ai-slack-part-1-3-69c7e38b7b1e#.g2aceuncf">Chatbot Using Django REST Framework + api.ai + Slack — Part 1/3</a></li>
|
||||
<li><a href="https://blog.levit.be/new-django-admin-with-emberjs-what-are-the-news/">New Django Admin with DRF and EmberJS... What are the News?</a></li>
|
||||
<li><a href="https://medium.com/django-rest-framework">Blog posts about Django REST Framework</a></li>
|
||||
|
|
|
@ -475,7 +475,7 @@ YAML-based OpenAPI format.</p>
|
|||
</code></pre>
|
||||
<p>We can now include a schema for our API, by including an autogenerated schema
|
||||
view in our URL configuration.</p>
|
||||
<pre><code class="python">from rest_framework.schemas import get_schema_view
|
||||
<pre><code class="language-python">from rest_framework.schemas import get_schema_view
|
||||
|
||||
schema_view = get_schema_view(title='Pastebin API')
|
||||
|
||||
|
@ -484,7 +484,6 @@ urlpatterns = [
|
|||
...
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<p>If you visit the <code>/schema/</code> endpoint in a browser you should now see <code>corejson</code>
|
||||
representation become available as an option.</p>
|
||||
<p><img alt="Schema format" src="../../img/corejson-format.png" /></p>
|
||||
|
|
|
@ -429,12 +429,11 @@
|
|||
<p>See the <a href="/community/3.10-announcement.md">Version 3.10 Release Announcement</a> for more details.</p>
|
||||
<hr />
|
||||
<p>You can continue to use CoreAPI schemas by setting the appropriate default schema class:</p>
|
||||
<pre><code class="python"># In settings.py
|
||||
<pre><code class="language-python"># In settings.py
|
||||
REST_FRAMEWORK = {
|
||||
'DEFAULT_SCHEMA_CLASS': 'rest_framework.schemas.coreapi.AutoSchema',
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
<p>Under-the-hood, any subclass of <code>coreapi.AutoSchema</code> here will trigger use of the old CoreAPI schemas.
|
||||
<strong>Otherwise</strong> you will automatically be opted-in to the new OpenAPI schemas.</p>
|
||||
<p>All CoreAPI related code will be removed in Django REST Framework v3.12. Switch to OpenAPI schemas by then.</p>
|
||||
|
|
|
@ -586,9 +586,8 @@ can render the schema into the commonly used YAML-based OpenAPI format.</p>
|
|||
<p>There are two different ways you can serve a schema description for your API.</p>
|
||||
<h3 id="generating-a-schema-with-the-generateschema-management-command"><a class="toclink" href="#generating-a-schema-with-the-generateschema-management-command">Generating a schema with the <code>generateschema</code> management command</a></h3>
|
||||
<p>To generate a static API schema, use the <code>generateschema</code> management command.</p>
|
||||
<pre><code class="shell">$ python manage.py generateschema > schema.yml
|
||||
<pre><code class="language-shell">$ python manage.py generateschema > schema.yml
|
||||
</code></pre>
|
||||
|
||||
<p>Once you've generated a schema in this way you can annotate it with any
|
||||
additional information that cannot be automatically inferred by the schema
|
||||
generator.</p>
|
||||
|
@ -596,7 +595,7 @@ generator.</p>
|
|||
with each new release, or serve the API schema from your site's static media.</p>
|
||||
<h3 id="adding-a-view-with-get_schema_view"><a class="toclink" href="#adding-a-view-with-get_schema_view">Adding a view with <code>get_schema_view</code></a></h3>
|
||||
<p>To add a dynamically generated schema view to your API, use <code>get_schema_view</code>.</p>
|
||||
<pre><code class="python">from rest_framework.schemas import get_schema_view
|
||||
<pre><code class="language-python">from rest_framework.schemas import get_schema_view
|
||||
from django.urls import path
|
||||
|
||||
schema_view = get_schema_view(title="Example API")
|
||||
|
@ -606,7 +605,6 @@ urlpatterns = [
|
|||
...
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<p>See below <a href="#the-get_schema_view-shortcut">for more details</a> on customizing a
|
||||
dynamically generated schema view.</p>
|
||||
<h2 id="internal-schema-representation"><a class="toclink" href="#internal-schema-representation">Internal schema representation</a></h2>
|
||||
|
@ -1076,7 +1074,7 @@ that do not expect a request body.</p>
|
|||
<h3 id="get_manual_fieldsself-path-method"><a class="toclink" href="#get_manual_fieldsself-path-method">get_manual_fields(self, path, method)</a></h3>
|
||||
<p>Return a list of <code>coreapi.Field()</code> instances to be added to or replace generated fields. Defaults to (optional) <code>manual_fields</code> passed to <code>AutoSchema</code> constructor.</p>
|
||||
<p>May be overridden to customise manual fields by <code>path</code> or <code>method</code>. For example, a per-method adjustment may look like this:</p>
|
||||
<pre><code class="python">def get_manual_fields(self, path, method):
|
||||
<pre><code class="language-python">def get_manual_fields(self, path, method):
|
||||
"""Example adding per-method fields."""
|
||||
|
||||
extra_fields = []
|
||||
|
@ -1088,7 +1086,6 @@ that do not expect a request body.</p>
|
|||
manual_fields = super().get_manual_fields(path, method)
|
||||
return manual_fields + extra_fields
|
||||
</code></pre>
|
||||
|
||||
<h3 id="update_fieldsfields-update_with"><a class="toclink" href="#update_fieldsfields-update_with">update_fields(fields, update_with)</a></h3>
|
||||
<p>Utility <code>staticmethod</code>. Encapsulates logic to add or replace fields from a list
|
||||
by <code>Field.name</code>. May be overridden to adjust replacement criteria.</p>
|
||||
|
|
|
@ -545,7 +545,6 @@ continued development by <strong><a href="community/funding/">signing up for a p
|
|||
<li><a href="https://retool.com/?utm_source=djangorest&utm_medium=sponsorship" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/retool-sidebar.png)">Retool</a></li>
|
||||
<li><a href="https://bit.io/jobs?utm_source=DRF&utm_medium=sponsor&utm_campaign=DRF_sponsorship" style="background-image: url(https://fund-rest-framework.s3.amazonaws.com/bitio_logo_gold_background.png)">bit.io</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">wonderful sponsors</a>, and in particular to our premium backers, <a href="https://getsentry.com/welcome/">Sentry</a>, <a href="https://getstream.io/?utm_source=drf&utm_medium=banner&utm_campaign=drf">Stream</a>, <a href="https://software.esg-usa.com/">ESG</a>, <a href="https://rollbar.com/?utm_source=django&utm_medium=sponsorship&utm_campaign=freetrial">Rollbar</a>, <a href="https://cadre.com">Cadre</a>, <a href="https://hubs.ly/H0f30Lf0">Kloudless</a>, <a href="https://lightsonsoftware.com">Lights On Software</a>, <a href="https://retool.com/?utm_source=djangorest&utm_medium=sponsorship">Retool</a>, and <a href="https://bit.io/jobs?utm_source=DRF&utm_medium=sponsor&utm_campaign=DRF_sponsorship">bit.io</a>.</em></p>
|
||||
|
@ -640,8 +639,9 @@ Framework.</p>
|
|||
<p>For support please see the <a href="https://groups.google.com/forum/?fromgroups#!forum/django-rest-framework">REST framework discussion group</a>, try the <code>#restframework</code> channel on <code>irc.freenode.net</code>, search <a href="https://botbot.me/freenode/restframework/">the IRC archives</a>, or raise a question on <a href="https://stackoverflow.com/">Stack Overflow</a>, making sure to include the <a href="https://stackoverflow.com/questions/tagged/django-rest-framework">'django-rest-framework'</a> tag.</p>
|
||||
<p>For priority support please sign up for a <a href="https://fund.django-rest-framework.org/topics/funding/">professional or premium sponsorship plan</a>.</p>
|
||||
<p>For updates on REST framework development, you may also want to follow <a href="https://twitter.com/_tomchristie">the author</a> on Twitter.</p>
|
||||
<p><a style="padding-top: 10px" href="https://twitter.com/_tomchristie" class="twitter-follow-button" data-show-count="false">Follow @_tomchristie</a>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script></p>
|
||||
<p><a style="padding-top: 10px" href="https://twitter.com/_tomchristie" class="twitter-follow-button" data-show-count="false">Follow @_tomchristie</a></p>
|
||||
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
||||
|
||||
<h2 id="security"><a class="toclink" href="#security">Security</a></h2>
|
||||
<p>If you believe you’ve found something in Django REST framework which has security implications, please <strong>do not raise the issue in a public forum</strong>.</p>
|
||||
<p>Send a description of the issue via email to <a href="mailto:rest-framework-security@googlegroups.com">rest-framework-security@googlegroups.com</a>. The project maintainers will then work with you to resolve any issues where required, prior to any public disclosure.</p>
|
||||
|
|
File diff suppressed because one or more lines are too long
132
sitemap.xml
132
sitemap.xml
|
@ -1,267 +1,267 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"><url>
|
||||
<loc>https://www.django-rest-framework.org/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/tutorial/quickstart/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/tutorial/1-serialization/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/tutorial/2-requests-and-responses/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/tutorial/3-class-based-views/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/tutorial/4-authentication-and-permissions/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/tutorial/5-relationships-and-hyperlinked-apis/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/tutorial/6-viewsets-and-routers/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/requests/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/responses/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/views/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/generic-views/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/viewsets/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/routers/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/parsers/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/renderers/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/serializers/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/fields/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/relations/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/validators/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/authentication/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/permissions/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/caching/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/throttling/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/filtering/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/pagination/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/versioning/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/content-negotiation/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/metadata/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/schemas/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/format-suffixes/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/reverse/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/exceptions/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/status-codes/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/testing/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/api-guide/settings/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/documenting-your-api/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/api-clients/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/internationalization/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/ajax-csrf-cors/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/html-and-forms/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/browser-enhancements/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/browsable-api/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/topics/rest-hypermedia-hateoas/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/tutorials-and-resources/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/third-party-packages/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/contributing/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/project-management/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/release-notes/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.12-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.11-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.10-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.9-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.8-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.7-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.6-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.5-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.4-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.3-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.2-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.1-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/3.0-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/kickstarter-announcement/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/mozilla-grant/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/funding/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url><url>
|
||||
<loc>https://www.django-rest-framework.org/community/jobs/</loc>
|
||||
<lastmod>2020-09-30</lastmod>
|
||||
<lastmod>2020-11-05</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
</url>
|
||||
</urlset>
|
BIN
sitemap.xml.gz
BIN
sitemap.xml.gz
Binary file not shown.
|
@ -458,7 +458,7 @@ dynamic <code>SchemaView</code> endpoint.</p>
|
|||
<p>Assuming you've followed the example from the schemas documentation for routing
|
||||
a dynamic <code>SchemaView</code>, a minimal Django template for using Swagger UI might be
|
||||
this:</p>
|
||||
<pre><code class="html"><!DOCTYPE html>
|
||||
<pre><code class="language-html"><!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Swagger</title>
|
||||
|
@ -487,10 +487,9 @@ this:</p>
|
|||
</body>
|
||||
</html>
|
||||
</code></pre>
|
||||
|
||||
<p>Save this in your templates folder as <code>swagger-ui.html</code>. Then route a
|
||||
<code>TemplateView</code> in your project's URL conf:</p>
|
||||
<pre><code class="python">from django.views.generic import TemplateView
|
||||
<pre><code class="language-python">from django.views.generic import TemplateView
|
||||
|
||||
urlpatterns = [
|
||||
# ...
|
||||
|
@ -502,13 +501,12 @@ urlpatterns = [
|
|||
), name='swagger-ui'),
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<p>See the <a href="https://swagger.io/tools/swagger-ui/">Swagger UI documentation</a> for advanced usage.</p>
|
||||
<h3 id="a-minimal-example-with-redoc"><a class="toclink" href="#a-minimal-example-with-redoc">A minimal example with ReDoc.</a></h3>
|
||||
<p>Assuming you've followed the example from the schemas documentation for routing
|
||||
a dynamic <code>SchemaView</code>, a minimal Django template for using ReDoc might be
|
||||
this:</p>
|
||||
<pre><code class="html"><!DOCTYPE html>
|
||||
<pre><code class="language-html"><!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>ReDoc</title>
|
||||
|
@ -530,10 +528,9 @@ this:</p>
|
|||
</body>
|
||||
</html>
|
||||
</code></pre>
|
||||
|
||||
<p>Save this in your templates folder as <code>redoc.html</code>. Then route a <code>TemplateView</code>
|
||||
in your project's URL conf:</p>
|
||||
<pre><code class="python">from django.views.generic import TemplateView
|
||||
<pre><code class="language-python">from django.views.generic import TemplateView
|
||||
|
||||
urlpatterns = [
|
||||
# ...
|
||||
|
@ -545,7 +542,6 @@ urlpatterns = [
|
|||
), name='redoc'),
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<p>See the <a href="https://github.com/Rebilly/ReDoc">ReDoc documentation</a> for advanced usage.</p>
|
||||
<h2 id="third-party-packages"><a class="toclink" href="#third-party-packages">Third party packages</a></h2>
|
||||
<p>There are a number of mature third-party packages for providing API documentation.</p>
|
||||
|
@ -585,7 +581,7 @@ documentation and more. Several popular plugins for DRF are supported out-of-the
|
|||
[ref]: http://example.com/activating-accounts
|
||||
"""
|
||||
</code></pre>
|
||||
<p>Note that when using viewsets the basic docstring is used for all generated views. To provide descriptions for each view, such as for the list and retrieve views, use docstring sections as described in <a href="../api-guide/schemas/#examples">Schemas as documentation: Examples</a>.</p>
|
||||
<p>Note that when using viewsets the basic docstring is used for all generated views. To provide descriptions for each view, such as for the list and retrieve views, use docstring sections as described in <a href="../../api-guide/schemas/#examples">Schemas as documentation: Examples</a>.</p>
|
||||
<h4 id="the-options-method"><a class="toclink" href="#the-options-method">The <code>OPTIONS</code> method</a></h4>
|
||||
<p>REST framework APIs also support programmatically accessible descriptions, using the <code>OPTIONS</code> HTTP method. A view will respond to an <code>OPTIONS</code> request with metadata including the name, description, and the various media types it accepts and responds with.</p>
|
||||
<p>When using the generic views, any <code>OPTIONS</code> requests will additionally respond with metadata regarding any <code>POST</code> or <code>PUT</code> actions available, describing which fields are on the serializer.</p>
|
||||
|
@ -599,7 +595,7 @@ documentation and more. Several popular plugins for DRF are supported out-of-the
|
|||
data.pop('description')
|
||||
return data
|
||||
</code></pre>
|
||||
<p>See <a href="../api-guide/metadata/">the Metadata docs</a> for more details.</p>
|
||||
<p>See <a href="../../api-guide/metadata/">the Metadata docs</a> for more details.</p>
|
||||
<hr />
|
||||
<h2 id="the-hypermedia-approach"><a class="toclink" href="#the-hypermedia-approach">The hypermedia approach</a></h2>
|
||||
<p>To be fully RESTful an API should present its available actions as hypermedia controls in the responses that it sends.</p>
|
||||
|
|
|
@ -442,7 +442,7 @@
|
|||
|
||||
<h1 id="tutorial-6-viewsets-routers"><a class="toclink" href="#tutorial-6-viewsets-routers">Tutorial 6: ViewSets & Routers</a></h1>
|
||||
<p>REST framework includes an abstraction for dealing with <code>ViewSets</code>, that allows the developer to concentrate on modeling the state and interactions of the API, and leave the URL construction to be handled automatically, based on common conventions.</p>
|
||||
<p><code>ViewSet</code> classes are almost the same thing as <code>View</code> classes, except that they provide operations such as <code>read</code>, or <code>update</code>, and not method handlers such as <code>get</code> or <code>put</code>.</p>
|
||||
<p><code>ViewSet</code> classes are almost the same thing as <code>View</code> classes, except that they provide operations such as <code>retrieve</code>, or <code>update</code>, and not method handlers such as <code>get</code> or <code>put</code>.</p>
|
||||
<p>A <code>ViewSet</code> class is only bound to a set of method handlers at the last moment, when it is instantiated into a set of views, typically by using a <code>Router</code> class which handles the complexities of defining the URL conf for you.</p>
|
||||
<h2 id="refactoring-to-use-viewsets"><a class="toclink" href="#refactoring-to-use-viewsets">Refactoring to use ViewSets</a></h2>
|
||||
<p>Let's take our current set of views, and refactor them into view sets.</p>
|
||||
|
@ -451,7 +451,7 @@
|
|||
|
||||
class UserViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
This viewset automatically provides `list` and `detail` actions.
|
||||
This viewset automatically provides `list` and `retrieve` actions.
|
||||
"""
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
|
@ -460,6 +460,7 @@ class UserViewSet(viewsets.ReadOnlyModelViewSet):
|
|||
<p>Next we're going to replace the <code>SnippetList</code>, <code>SnippetDetail</code> and <code>SnippetHighlight</code> view classes. We can remove the three views, and again replace them with a single class.</p>
|
||||
<pre><code>from rest_framework.decorators import action
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import permissions
|
||||
|
||||
class SnippetViewSet(viewsets.ModelViewSet):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue
Block a user