mirror of
https://github.com/encode/django-rest-framework.git
synced 2026-01-16 13:28:49 +03:00
Update documentation
This commit is contained in:
parent
43f35f0cdc
commit
6763d88845
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Authentication - Django REST framework</title>
|
||||
<title>Authentication</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/authentication/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../permissions">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../permissions/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../validators">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../validators/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Authentication</a>
|
||||
<a href="./">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -429,6 +433,10 @@
|
|||
<a href="#hawk-http-authentication">Hawk HTTP Authentication</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#http-signature-authentication">HTTP Signature Authentication</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#djoser">Djoser</a>
|
||||
</li>
|
||||
|
|
@ -461,14 +469,14 @@
|
|||
<p>Auth needs to be pluggable.</p>
|
||||
<p>— Jacob Kaplan-Moss, <a href="http://jacobian.org/writing/rest-worst-practices/">"REST worst practices"</a></p>
|
||||
</blockquote>
|
||||
<p>Authentication is the mechanism of associating an incoming request with a set of identifying credentials, such as the user the request came from, or the token that it was signed with. The <a href="../permissions">permission</a> and <a href="../throttling">throttling</a> policies can then use those credentials to determine if the request should be permitted.</p>
|
||||
<p>Authentication is the mechanism of associating an incoming request with a set of identifying credentials, such as the user the request came from, or the token that it was signed with. The <a href="../permissions/">permission</a> and <a href="../throttling/">throttling</a> policies can then use those credentials to determine if the request should be permitted.</p>
|
||||
<p>REST framework provides a number of authentication schemes out of the box, and also allows you to implement custom schemes.</p>
|
||||
<p>Authentication is always run at the very start of the view, before the permission and throttling checks occur, and before any other code is allowed to proceed.</p>
|
||||
<p>The <code>request.user</code> property will typically be set to an instance of the <code>contrib.auth</code> package's <code>User</code> class.</p>
|
||||
<p>The <code>request.auth</code> property is used for any additional authentication information, for example, it may be used to represent an authentication token that the request was signed with.</p>
|
||||
<hr />
|
||||
<p><strong>Note:</strong> Don't forget that <strong>authentication by itself won't allow or disallow an incoming request</strong>, it simply identifies the credentials that the request was made with.</p>
|
||||
<p>For information on how to setup the permission polices for your API please see the <a href="../permissions">permissions documentation</a>.</p>
|
||||
<p>For information on how to setup the permission polices for your API please see the <a href="../permissions/">permissions documentation</a>.</p>
|
||||
<hr />
|
||||
<h2 id="how-authentication-is-determined">How authentication is determined</h2>
|
||||
<p>The authentication schemes are always defined as a list of classes. REST framework will attempt to authenticate with each class in the list, and will set <code>request.user</code> and <code>request.auth</code> using the return value of the first class that successfully authenticates.</p>
|
||||
|
|
@ -577,7 +585,6 @@ print token.key
|
|||
<h4 id="generating-tokens">Generating Tokens</h4>
|
||||
<p>If you want every user to have an automatically generated Token, you can simply catch the User's <code>post_save</code> signal.</p>
|
||||
<pre><code>from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db.models.signals import post_save
|
||||
from django.dispatch import receiver
|
||||
from rest_framework.authtoken.models import Token
|
||||
|
|
@ -704,11 +711,12 @@ REST_FRAMEWORK = {
|
|||
<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">Hawk HTTP Authentication</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>
|
||||
<h2 id="http-signature-authentication">HTTP Signature Authentication</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">Djoser</h2>
|
||||
<p><a href="https://github.com/sunscrapers/djoser">Djoser</a> library provides a set of views to handle basic actions such as registration, login, logout, password reset and account activation. The package works with a custom user model and it uses token based authentication. This is a ready to use REST implementation of Django authentication system.</p>
|
||||
<h2 id="django-rest-auth">django-rest-auth</h2>
|
||||
<p><a href="https://github.com/Tivix/django-rest-auth">Django-rest-auth</a> library provides a set of REST API endpoints for registration, authentication (including social media authentication), password reset, retrieve and update user details, etc. By having these API endpoints, your client apps such as AngularJS, iOS, Android, and others can communicate to your Django backend site independently via REST APIs for user management.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Content negotiation - Django REST framework</title>
|
||||
<title>Content negotiation</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/content-negotiation/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../metadata">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../metadata/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../versioning">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../versioning/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Content negotiation</a>
|
||||
<a href="./">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -460,7 +464,6 @@ class NoNegotiationView(APIView):
|
|||
'accepted media type': request.accepted_renderer.media_type
|
||||
})
|
||||
</code></pre>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Exceptions - Django REST framework</title>
|
||||
<title>Exceptions</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/exceptions/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../status-codes">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../status-codes/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../reverse">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../reverse/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Exceptions</a>
|
||||
<a href="./">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -518,11 +522,11 @@ class ServiceUnavailable(APIException):
|
|||
<h2 id="authenticationfailed">AuthenticationFailed</h2>
|
||||
<p><strong>Signature:</strong> <code>AuthenticationFailed(detail=None)</code></p>
|
||||
<p>Raised when an incoming request includes incorrect authentication.</p>
|
||||
<p>By default this exception results in a response with the HTTP status code "401 Unauthenticated", but it may also result in a "403 Forbidden" response, depending on the authentication scheme in use. See the <a href="../authentication">authentication documentation</a> for more details.</p>
|
||||
<p>By default this exception results in a response with the HTTP status code "401 Unauthenticated", but it may also result in a "403 Forbidden" response, depending on the authentication scheme in use. See the <a href="../authentication/">authentication documentation</a> for more details.</p>
|
||||
<h2 id="notauthenticated">NotAuthenticated</h2>
|
||||
<p><strong>Signature:</strong> <code>NotAuthenticated(detail=None)</code></p>
|
||||
<p>Raised when an unauthenticated request fails the permission checks.</p>
|
||||
<p>By default this exception results in a response with the HTTP status code "401 Unauthenticated", but it may also result in a "403 Forbidden" response, depending on the authentication scheme in use. See the <a href="../authentication">authentication documentation</a> for more details.</p>
|
||||
<p>By default this exception results in a response with the HTTP status code "401 Unauthenticated", but it may also result in a "403 Forbidden" response, depending on the authentication scheme in use. See the <a href="../authentication/">authentication documentation</a> for more details.</p>
|
||||
<h2 id="permissiondenied">PermissionDenied</h2>
|
||||
<p><strong>Signature:</strong> <code>PermissionDenied(detail=None)</code></p>
|
||||
<p>Raised when an authenticated request fails the permission checks.</p>
|
||||
|
|
@ -560,7 +564,6 @@ class ServiceUnavailable(APIException):
|
|||
</code></pre>
|
||||
<p>The generic views use the <code>raise_exception=True</code> flag, which means that you can override the style of validation error responses globally in your API. To do so, use a custom exception handler, as described above.</p>
|
||||
<p>By default this exception results in a response with the HTTP status code "400 Bad Request".</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Serializer fields - Django REST framework</title>
|
||||
<title>Serializer fields</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/fields/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../relations">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../relations/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../serializers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../serializers/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Serializer fields</a>
|
||||
<a href="./">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -851,10 +855,10 @@ Django's regular <a href="https://docs.djangoproject.com/en/dev/ref/settings/#st
|
|||
<p>A field class that does not take a value based on user input, but instead takes its value from a default value or callable.</p>
|
||||
<p><strong>Signature</strong>: <code>HiddenField()</code></p>
|
||||
<p>For example, to include a field that always provides the current time as part of the serializer validated data, you would use the following:</p>
|
||||
<pre><code>modified = serializer.HiddenField(default=timezone.now)
|
||||
<pre><code>modified = serializers.HiddenField(default=timezone.now)
|
||||
</code></pre>
|
||||
<p>The <code>HiddenField</code> class is usually only needed if you have some validation that needs to run based on some pre-provided field values, but you do not want to expose all of those fields to the end user.</p>
|
||||
<p>For further examples on <code>HiddenField</code> see the <a href="../validators">validators</a> documentation.</p>
|
||||
<p>For further examples on <code>HiddenField</code> see the <a href="../validators/">validators</a> documentation.</p>
|
||||
<h2 id="modelfield">ModelField</h2>
|
||||
<p>A generic field that can be tied to any arbitrary model field. The <code>ModelField</code> class delegates the task of serialization/deserialization to its associated model field. This field can be used to create serializer fields for custom model fields, without having to create a new custom serializer field.</p>
|
||||
<p>This field is used by <code>ModelSerializer</code> to correspond to custom model field classes.</p>
|
||||
|
|
@ -884,7 +888,7 @@ class UserSerializer(serializers.ModelSerializer):
|
|||
<h1 id="custom-fields">Custom fields</h1>
|
||||
<p>If you want to create a custom field, you'll need to subclass <code>Field</code> and then override either one or both of the <code>.to_representation()</code> and <code>.to_internal_value()</code> methods. These two methods are used to convert between the initial datatype, and a primitive, serializable datatype. Primitive datatypes will typically be any of a number, string, boolean, <code>date</code>/<code>time</code>/<code>datetime</code> or <code>None</code>. They may also be any list or dictionary like object that only contains other primitive objects. Other types might be supported, depending on the renderer that you are using.</p>
|
||||
<p>The <code>.to_representation()</code> method is called to convert the initial datatype into a primitive, serializable datatype.</p>
|
||||
<p>The <code>to_internal_value()</code> method is called to restore a primitive datatype into its internal python representation. This method should raise a <code>serializer.ValidationError</code> if the data is invalid.</p>
|
||||
<p>The <code>to_internal_value()</code> method is called to restore a primitive datatype into its internal python representation. This method should raise a <code>serializers.ValidationError</code> if the data is invalid.</p>
|
||||
<p>Note that the <code>WritableField</code> class that was present in version 2.x no longer exists. You should subclass <code>Field</code> and override <code>to_internal_value()</code> if the field supports data input.</p>
|
||||
<h2 id="examples">Examples</h2>
|
||||
<p>Let's look at an example of serializing a class that represents an RGB color value:</p>
|
||||
|
|
@ -978,7 +982,6 @@ def to_internal_value(self, data):
|
|||
<p>The <a href="https://github.com/djangonauts/django-rest-framework-gis">django-rest-framework-gis</a> package provides geographic addons for django rest framework like a <code>GeometryField</code> field and a GeoJSON serializer.</p>
|
||||
<h2 id="django-rest-framework-hstore">django-rest-framework-hstore</h2>
|
||||
<p>The <a href="https://github.com/djangonauts/django-rest-framework-hstore">django-rest-framework-hstore</a> package provides an <code>HStoreField</code> to support <a href="https://github.com/djangonauts/django-hstore">django-hstore</a> <code>DictionaryField</code> model field.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Filtering - Django REST framework</title>
|
||||
<title>Filtering</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/filtering/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../pagination">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../pagination/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../throttling">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../throttling/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Filtering</a>
|
||||
<a href="./">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -429,6 +433,10 @@
|
|||
<a href="#django-rest-framework-filters-package">Django REST framework filters package</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#django-rest-framework-full-word-search-filter">Django REST framework full word search filter</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -504,7 +512,7 @@ class PurchaseList(generics.ListAPIView):
|
|||
by filtering against a `username` query parameter in the URL.
|
||||
"""
|
||||
queryset = Purchase.objects.all()
|
||||
username = self.request.QUERY_PARAMS.get('username', None)
|
||||
username = self.request.query_params.get('username', None)
|
||||
if username is not None:
|
||||
queryset = queryset.filter(purchaser__username=username)
|
||||
return queryset
|
||||
|
|
@ -751,7 +759,8 @@ class ProductFilter(django_filters.FilterSet):
|
|||
<p>The following third party packages provide additional filter implementations.</p>
|
||||
<h2 id="django-rest-framework-filters-package">Django REST framework filters package</h2>
|
||||
<p>The <a href="https://github.com/philipn/django-rest-framework-filters">django-rest-framework-filters package</a> works together with the <code>DjangoFilterBackend</code> class, and allows you to easily create filters across relationships, or create multiple filter lookup types for a given field.</p>
|
||||
|
||||
<h2 id="django-rest-framework-full-word-search-filter">Django REST framework full word search filter</h2>
|
||||
<p>The <a href="https://github.com/trollknurr/django-rest-framework-word-search-filter">djangorestframework-word-filter</a> developed as alternative to <code>filters.SearchFilter</code> which will search full word in text, or exact match.</p>
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Format suffixes - Django REST framework</title>
|
||||
<title>Format suffixes</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/format-suffixes/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../reverse">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../reverse/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../metadata">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../metadata/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Format suffixes</a>
|
||||
<a href="./">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -436,7 +440,6 @@ urlpatterns = i18n_patterns(
|
|||
<p>It is actually a misconception. For example, take the following quote from Roy Fielding discussing the relative merits of query parameter media-type indicators vs. file extension media-type indicators:</p>
|
||||
<p>“That's why I always prefer extensions. Neither choice has anything to do with REST.” — Roy Fielding, <a href="http://tech.groups.yahoo.com/group/rest-discuss/message/14844">REST discuss mailing list</a></p>
|
||||
<p>The quote does not mention Accept headers, but it does make it clear that format suffixes should be considered an acceptable pattern.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Generic views - Django REST framework</title>
|
||||
<title>Generic views</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/generic-views/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../viewsets">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../viewsets/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../views">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../views/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Generic views</a>
|
||||
<a href="./">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -538,7 +542,7 @@ class UserList(generics.ListCreateAPIView):
|
|||
return Response(serializer.data)
|
||||
</code></pre>
|
||||
<p>For very simple cases you might want to pass through any class attributes using the <code>.as_view()</code> method. For example, your URLconf might include something like the following entry:</p>
|
||||
<pre><code>url(r'^/users/', ListCreateAPIView.as_view(model=User), name='user-list')
|
||||
<pre><code>url(r'^/users/', ListCreateAPIView.as_view(queryset=User.objects.all(), serializer_class=UserSerializer), name='user-list')
|
||||
</code></pre>
|
||||
<hr />
|
||||
<h1 id="api-reference">API Reference</h1>
|
||||
|
|
@ -592,12 +596,12 @@ class UserList(generics.ListCreateAPIView):
|
|||
<p>Note that if your API doesn't include any object level permissions, you may optionally exclude the <code>self.check_object_permissions</code>, and simply return the object from the <code>get_object_or_404</code> lookup.</p>
|
||||
<h4 id="get_filter_backendsself"><code>get_filter_backends(self)</code></h4>
|
||||
<p>Returns the classes that should be used to filter the queryset. Defaults to returning the <code>filter_backends</code> attribute.</p>
|
||||
<p>May be overridden to provide more complex behavior with filters, such as using different (or even exlusive) lists of filter_backends depending on different criteria.</p>
|
||||
<p>May be overridden to provide more complex behavior with filters, such as using different (or even exclusive) lists of filter_backends depending on different criteria.</p>
|
||||
<p>For example:</p>
|
||||
<pre><code>def get_filter_backends(self):
|
||||
if "geo_route" in self.request.QUERY_PARAMS:
|
||||
if "geo_route" in self.request.query_params:
|
||||
return (GeoRouteFilter, CategoryFilter)
|
||||
elif "geo_point" in self.request.QUERY_PARAMS:
|
||||
elif "geo_point" in self.request.query_params:
|
||||
return (GeoPointFilter, CategoryFilter)
|
||||
|
||||
return (CategoryFilter,)
|
||||
|
|
@ -642,7 +646,7 @@ class UserList(generics.ListCreateAPIView):
|
|||
<ul>
|
||||
<li><code>get_serializer_context(self)</code> - Returns a dictionary containing any extra context that should be supplied to the serializer. Defaults to including <code>'request'</code>, <code>'view'</code> and <code>'format'</code> keys.</li>
|
||||
<li><code>get_serializer(self, instance=None, data=None, files=None, many=False, partial=False, allow_add_remove=False)</code> - Returns a serializer instance.</li>
|
||||
<li><code>get_pagination_serializer(self, page)</code> - Returns a serializer instance to use with paginated data.</li>
|
||||
<li><code>get_paginated_response(self, data)</code> - Returns a paginated style <code>Response</code> object.</li>
|
||||
<li><code>paginate_queryset(self, queryset)</code> - Paginate a queryset if required, either returning a page object, or <code>None</code> if pagination is not configured for this view.</li>
|
||||
<li><code>filter_queryset(self, queryset)</code> - Given a queryset, filter it with whichever filter backends are in use, returning a new queryset.</li>
|
||||
</ul>
|
||||
|
|
@ -756,7 +760,6 @@ class BaseRetrieveUpdateDestroyView(MultipleFieldLookupMixin,
|
|||
<p>The following third party packages provide additional generic view implementations.</p>
|
||||
<h2 id="django-rest-framework-bulk">Django REST Framework bulk</h2>
|
||||
<p>The <a href="https://github.com/miki725/django-rest-framework-bulk">django-rest-framework-bulk package</a> implements generic view mixins as well as some common concrete generic views to allow to apply bulk operations via API requests.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Metadata - Django REST framework</title>
|
||||
<title>Metadata</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/metadata/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../format-suffixes">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../format-suffixes/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../content-negotiation">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../content-negotiation/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Metadata</a>
|
||||
<a href="./">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -468,7 +472,6 @@ def schema(self, request):
|
|||
'description': view.get_view_description()
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Pagination - Django REST framework</title>
|
||||
<title>Pagination</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/pagination/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../versioning">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../versioning/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../filtering">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../filtering/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Pagination</a>
|
||||
<a href="./">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -652,7 +656,7 @@ class StandardResultsSetPagination(PageNumberPagination):
|
|||
</code></pre>
|
||||
<p>API responses for list endpoints will now include a <code>Link</code> header, instead of including the pagination links as part of the body of the response, for example:</p>
|
||||
<hr />
|
||||
<p><img alt="Link Header" src="../../../img/link-header-pagination.png" /></p>
|
||||
<p><img alt="Link Header" src="../../img/link-header-pagination.png" /></p>
|
||||
<p><em>A custom pagination style, using the 'Link' header'</em></p>
|
||||
<hr />
|
||||
<h1 id="html-pagination-controls">HTML pagination controls</h1>
|
||||
|
|
@ -673,7 +677,6 @@ class StandardResultsSetPagination(PageNumberPagination):
|
|||
<p>The following third party packages are also available.</p>
|
||||
<h2 id="drf-extensions">DRF-extensions</h2>
|
||||
<p>The <a href="http://chibisov.github.io/drf-extensions/docs/"><code>DRF-extensions</code> package</a> includes a <a href="http://chibisov.github.io/drf-extensions/docs/#paginatebymaxmixin"><code>PaginateByMaxMixin</code> mixin class</a> that allows your API clients to specify <code>?page_size=max</code> to obtain the maximum allowed page size.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Parsers - Django REST framework</title>
|
||||
<title>Parsers</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/parsers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../renderers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../renderers/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../routers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../routers/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Parsers</a>
|
||||
<a href="./">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -596,7 +600,6 @@ def parse(self, stream, media_type=None, parser_context=None):
|
|||
<p><a href="https://github.com/juanriaza/django-rest-framework-msgpack">MessagePack</a> is a fast, efficient binary serialization format. <a href="https://github.com/juanriaza">Juan Riaza</a> maintains the <a href="https://github.com/juanriaza/django-rest-framework-msgpack">djangorestframework-msgpack</a> package which provides MessagePack renderer and parser support for REST framework.</p>
|
||||
<h2 id="camelcase-json">CamelCase JSON</h2>
|
||||
<p><a href="https://github.com/vbabiy/djangorestframework-camel-case">djangorestframework-camel-case</a> provides camel case JSON renderers and parsers for REST framework. This allows serializers to use Python-style underscored field names, but be exposed in the API as Javascript-style camel case field names. It is maintained by <a href="https://github.com/vbabiy">Vitaly Babiy</a>.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Permissions - Django REST framework</title>
|
||||
<title>Permissions</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/permissions/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../throttling">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../throttling/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../authentication">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../authentication/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Permissions</a>
|
||||
<a href="./">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -453,7 +457,7 @@
|
|||
<p>Authentication or identification by itself is not usually sufficient to gain access to information or code. For that, the entity requesting access must have authorization.</p>
|
||||
<p>— <a href="https://developer.apple.com/library/mac/#documentation/security/Conceptual/AuthenticationAndAuthorizationGuide/Authorization/Authorization.html">Apple Developer Documentation</a></p>
|
||||
</blockquote>
|
||||
<p>Together with <a href="../authentication">authentication</a> and <a href="../throttling">throttling</a>, permissions determine whether a request should be granted or denied access.</p>
|
||||
<p>Together with <a href="../authentication/">authentication</a> and <a href="../throttling/">throttling</a>, permissions determine whether a request should be granted or denied access.</p>
|
||||
<p>Permission checks are always run at the very start of the view, before any other code is allowed to proceed. Permission checks will typically use the authentication information in the <code>request.user</code> and <code>request.auth</code> properties to determine if the incoming request should be permitted.</p>
|
||||
<p>Permissions are used to grant or deny access different classes of users to different parts of the API.</p>
|
||||
<p>The simplest style of permission would be to allow access to any authenticated user, and deny access to any unauthenticated user. This corresponds the <code>IsAuthenticated</code> class in REST framework.</p>
|
||||
|
|
@ -483,7 +487,7 @@ or if you override the <code>get_object</code> method on a generic view, then yo
|
|||
</code></pre>
|
||||
<h4 id="limitations-of-object-level-permissions">Limitations of object level permissions</h4>
|
||||
<p>For performance reasons the generic views will not automatically apply object level permissions to each instance in a queryset when returning a list of objects.</p>
|
||||
<p>Often when you're using object level permissions you'll also want to <a href="../filtering">filter the queryset</a> appropriately, to ensure that users only have visibility onto instances that they are permitted to view.</p>
|
||||
<p>Often when you're using object level permissions you'll also want to <a href="../filtering/">filter the queryset</a> appropriately, to ensure that users only have visibility onto instances that they are permitted to view.</p>
|
||||
<h2 id="setting-the-permission-policy">Setting the permission policy</h2>
|
||||
<p>The default permission policy may be set globally, using the <code>DEFAULT_PERMISSION_CLASSES</code> setting. For example.</p>
|
||||
<pre><code>REST_FRAMEWORK = {
|
||||
|
|
@ -552,7 +556,7 @@ def example_view(request, format=None):
|
|||
<p>Similar to <code>DjangoModelPermissions</code>, but also allows unauthenticated users to have read-only access to the API.</p>
|
||||
<h2 id="djangoobjectpermissions">DjangoObjectPermissions</h2>
|
||||
<p>This permission class ties into Django's standard <a href="https://docs.djangoproject.com/en/dev/topics/auth/customizing/#handling-object-permissions">object permissions framework</a> that allows per-object permissions on models. In order to use this permission class, you'll also need to add a permission backend that supports object-level permissions, such as <a href="https://github.com/lukaszb/django-guardian">django-guardian</a>.</p>
|
||||
<p>As with <code>DjangoModelPermissions</code>, this permission must only be applied to views that have a <code>.queryset</code> property. Authorization will only be granted if the user <em>is authenticated</em> and has the <em>relevant per-object permissions</em> and <em>relevant model permissions</em> assigned.</p>
|
||||
<p>As with <code>DjangoModelPermissions</code>, this permission must only be applied to views that have a <code>.queryset</code> property or <code>.get_queryset()</code> method. Authorization will only be granted if the user <em>is authenticated</em> and has the <em>relevant per-object permissions</em> and <em>relevant model permissions</em> assigned.</p>
|
||||
<ul>
|
||||
<li><code>POST</code> requests require the user to have the <code>add</code> permission on the model instance.</li>
|
||||
<li><code>PUT</code> and <code>PATCH</code> requests require the user to have the <code>change</code> permission on the model instance.</li>
|
||||
|
|
@ -611,7 +615,7 @@ class BlacklistPermission(permissions.BasePermission):
|
|||
return obj.owner == request.user
|
||||
</code></pre>
|
||||
<p>Note that the generic views will check the appropriate object level permissions, but if you're writing your own custom views, you'll need to make sure you check the object level permission checks yourself. You can do so by calling <code>self.check_object_permissions(request, obj)</code> from the view once you have the object instance. This call will raise an appropriate <code>APIException</code> if any object-level permission checks fail, and will otherwise simply return.</p>
|
||||
<p>Also note that the generic views will only check the object-level permissions for views that retrieve a single model instance. If you require object-level filtering of list views, you'll need to filter the queryset separately. See the <a href="../filtering">filtering documentation</a> for more details.</p>
|
||||
<p>Also note that the generic views will only check the object-level permissions for views that retrieve a single model instance. If you require object-level filtering of list views, you'll need to filter the queryset separately. See the <a href="../filtering/">filtering documentation</a> for more details.</p>
|
||||
<hr />
|
||||
<h1 id="third-party-packages">Third party packages</h1>
|
||||
<p>The following third party packages are also available.</p>
|
||||
|
|
@ -621,7 +625,6 @@ class BlacklistPermission(permissions.BasePermission):
|
|||
<p>The <a href="https://github.com/niwibe/djangorestframework-composed-permissions">Composed Permissions</a> package provides a simple way to define complex and multi-depth (with logic operators) permission objects, using small and reusable components.</p>
|
||||
<h2 id="rest-condition">REST Condition</h2>
|
||||
<p>The <a href="https://github.com/caxap/rest_condition">REST Condition</a> package is another extension for building complex permissions in a simple and convenient way. The extension allows you to combine permissions with logical operators.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Serializer relations - Django REST framework</title>
|
||||
<title>Serializer relations</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/relations/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../validators">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../validators/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../fields">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../fields/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Serializer relations</a>
|
||||
<a href="./">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -499,7 +503,7 @@ class Track(models.Model):
|
|||
|
||||
class Meta:
|
||||
unique_together = ('album', 'order')
|
||||
order_by = 'order'
|
||||
ordering = ['order']
|
||||
|
||||
def __unicode__(self):
|
||||
return '%d: %s' % (self.order, self.title)
|
||||
|
|
@ -690,7 +694,7 @@ class AlbumSerializer(serializers.ModelSerializer):
|
|||
<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>
|
||||
<h2 id="example_1">Example</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>
|
||||
<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>
|
||||
<pre><code>import time
|
||||
|
||||
class TrackListingField(serializers.RelatedField):
|
||||
|
|
@ -840,7 +844,6 @@ attributes are not configured to correctly match the URL conf.</p>
|
|||
<p>The following third party packages are also available.</p>
|
||||
<h2 id="drf-nested-routers">DRF Nested Routers</h2>
|
||||
<p>The <a href="https://github.com/alanjds/drf-nested-routers">drf-nested-routers package</a> provides routers and relationship fields for working with nested resources.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Renderers - Django REST framework</title>
|
||||
<title>Renderers</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/renderers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../serializers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../serializers/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../parsers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../parsers/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Renderers</a>
|
||||
<a href="./">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -513,7 +517,7 @@
|
|||
<h2 id="how-the-renderer-is-determined">How the renderer is determined</h2>
|
||||
<p>The set of valid renderers for a view is always defined as a list of classes. When a view is entered REST framework will perform content negotiation on the incoming request, and determine the most appropriate renderer to satisfy the request.</p>
|
||||
<p>The basic process of content negotiation involves examining the request's <code>Accept</code> header, to determine which media types it expects in the response. Optionally, format suffixes on the URL may be used to explicitly request a particular representation. For example the URL <code>http://example.com/api/users_count.json</code> might be an endpoint that always returns JSON data.</p>
|
||||
<p>For more information see the documentation on <a href="../content-negotiation">content negotiation</a>.</p>
|
||||
<p>For more information see the documentation on <a href="../content-negotiation/">content negotiation</a>.</p>
|
||||
<h2 id="setting-the-renderers">Setting the renderers</h2>
|
||||
<p>The default set of renderers may be set globally, using the <code>DEFAULT_RENDERER_CLASSES</code> setting. For example, the following settings would use <code>JSON</code> as the main media type and also include the self describing API.</p>
|
||||
<pre><code>REST_FRAMEWORK = {
|
||||
|
|
@ -586,7 +590,7 @@ Unlike other renderers, the data passed to the <code>Response</code> does not ne
|
|||
<p>An example of a view that uses <code>TemplateHTMLRenderer</code>:</p>
|
||||
<pre><code>class UserDetail(generics.RetrieveAPIView):
|
||||
"""
|
||||
A view that returns a templated HTML representations of a given user.
|
||||
A view that returns a templated HTML representation of a given user.
|
||||
"""
|
||||
queryset = User.objects.all()
|
||||
renderer_classes = (TemplateHTMLRenderer,)
|
||||
|
|
@ -603,14 +607,14 @@ Unlike other renderers, the data passed to the <code>Response</code> does not ne
|
|||
<p>See also: <code>StaticHTMLRenderer</code></p>
|
||||
<h2 id="statichtmlrenderer">StaticHTMLRenderer</h2>
|
||||
<p>A simple renderer that simply returns pre-rendered HTML. Unlike other renderers, the data passed to the response object should be a string representing the content to be returned.</p>
|
||||
<p>An example of a view that uses <code>TemplateHTMLRenderer</code>:</p>
|
||||
<p>An example of a view that uses <code>StaticHTMLRenderer</code>:</p>
|
||||
<pre><code>@api_view(('GET',))
|
||||
@renderer_classes((StaticHTMLRenderer,))
|
||||
def simple_html_view(request):
|
||||
data = '<html><body><h1>Hello, world</h1></body></html>'
|
||||
return Response(data)
|
||||
</code></pre>
|
||||
<p>You can use <code>TemplateHTMLRenderer</code> either to return regular HTML pages using REST framework, or to return both HTML and API responses from a single endpoint.</p>
|
||||
<p>You can use <code>StaticHTMLRenderer</code> either to return regular HTML pages using REST framework, or to return both HTML and API responses from a single endpoint.</p>
|
||||
<p><strong>.media_type</strong>: <code>text/html</code></p>
|
||||
<p><strong>.format</strong>: <code>'.html'</code></p>
|
||||
<p><strong>.charset</strong>: <code>utf-8</code></p>
|
||||
|
|
@ -635,7 +639,7 @@ def simple_html_view(request):
|
|||
return JSONRenderer()
|
||||
</code></pre>
|
||||
<h2 id="multipartrenderer">MultiPartRenderer</h2>
|
||||
<p>This renderer is used for rendering HTML multipart form data. <strong>It is not suitable as a response renderer</strong>, but is instead used for creating test requests, using REST framework's <a href="../testing">test client and test request factory</a>.</p>
|
||||
<p>This renderer is used for rendering HTML multipart form data. <strong>It is not suitable as a response renderer</strong>, but is instead used for creating test requests, using REST framework's <a href="../testing/">test client and test request factory</a>.</p>
|
||||
<p><strong>.media_type</strong>: <code>multipart/form-data; boundary=BoUnDaRyStRiNg</code></p>
|
||||
<p><strong>.format</strong>: <code>'.multipart'</code></p>
|
||||
<p><strong>.charset</strong>: <code>utf-8</code></p>
|
||||
|
|
@ -789,7 +793,7 @@ In this case you can underspecify the media types it should respond to, by using
|
|||
<p>Modify your REST framework settings.</p>
|
||||
<pre><code>REST_FRAMEWORK = {
|
||||
'DEFAULT_RENDERER_CLASSES': (
|
||||
'rest_framework_yaml.renderers.JSONPRenderer',
|
||||
'rest_framework_jsonp.renderers.JSONPRenderer',
|
||||
),
|
||||
}
|
||||
</code></pre>
|
||||
|
|
@ -803,7 +807,6 @@ In this case you can underspecify the media types it should respond to, by using
|
|||
<p><a href="https://github.com/vbabiy/djangorestframework-camel-case">djangorestframework-camel-case</a> provides camel case JSON renderers and parsers for REST framework. This allows serializers to use Python-style underscored field names, but be exposed in the API as Javascript-style camel case field names. It is maintained by <a href="https://github.com/vbabiy">Vitaly Babiy</a>.</p>
|
||||
<h2 id="pandas-csv-excel-png">Pandas (CSV, Excel, PNG)</h2>
|
||||
<p><a href="https://github.com/wq/django-rest-pandas">Django REST Pandas</a> provides a serializer and renderers that support additional data processing and output via the <a href="http://pandas.pydata.org/">Pandas</a> DataFrame API. Django REST Pandas includes renderers for Pandas-style CSV files, Excel workbooks (both <code>.xls</code> and <code>.xlsx</code>), and a number of <a href="https://github.com/wq/django-rest-pandas#supported-formats">other formats</a>. It is maintained by <a href="https://github.com/sheppard">S. Andrew Sheppard</a> as part of the <a href="https://github.com/wq">wq Project</a>.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Requests - Django REST framework</title>
|
||||
<title>Requests</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/requests/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../responses">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../responses/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../../tutorial/6-viewsets-and-routers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../../tutorial/6-viewsets-and-routers/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Requests</a>
|
||||
<a href="./">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -476,7 +480,7 @@
|
|||
<li>It supports parsing the content of HTTP methods other than <code>POST</code>, meaning that you can access the content of <code>PUT</code> and <code>PATCH</code> requests.</li>
|
||||
<li>It supports REST framework's flexible request parsing, rather than just supporting form data. For example you can handle incoming JSON data in the same way that you handle incoming form data.</li>
|
||||
</ul>
|
||||
<p>For more details see the <a href="../parsers">parsers documentation</a>.</p>
|
||||
<p>For more details see the <a href="../parsers/">parsers documentation</a>.</p>
|
||||
<h2 id="query_params">.query_params</h2>
|
||||
<p><code>request.query_params</code> is a more correctly named synonym for <code>request.GET</code>.</p>
|
||||
<p>For clarity inside your code, we recommend using <code>request.query_params</code> instead of the Django's standard <code>request.GET</code>. Doing so will help keep your codebase more correct and obvious - any HTTP method type may include query parameters, not just <code>GET</code> requests.</p>
|
||||
|
|
@ -508,11 +512,11 @@
|
|||
<h2 id="user">.user</h2>
|
||||
<p><code>request.user</code> typically returns an instance of <code>django.contrib.auth.models.User</code>, although the behavior depends on the authentication policy being used.</p>
|
||||
<p>If the request is unauthenticated the default value of <code>request.user</code> is an instance of <code>django.contrib.auth.models.AnonymousUser</code>.</p>
|
||||
<p>For more details see the <a href="../authentication">authentication documentation</a>.</p>
|
||||
<p>For more details see the <a href="../authentication/">authentication documentation</a>.</p>
|
||||
<h2 id="auth">.auth</h2>
|
||||
<p><code>request.auth</code> returns any additional authentication context. The exact behavior of <code>request.auth</code> depends on the authentication policy being used, but it may typically be an instance of the token that the request was authenticated against.</p>
|
||||
<p>If the request is unauthenticated, or if no additional context is present, the default value of <code>request.auth</code> is <code>None</code>.</p>
|
||||
<p>For more details see the <a href="../authentication">authentication documentation</a>.</p>
|
||||
<p>For more details see the <a href="../authentication/">authentication documentation</a>.</p>
|
||||
<h2 id="authenticators">.authenticators</h2>
|
||||
<p>The <code>APIView</code> class or <code>@api_view</code> decorator will ensure that this property is automatically set to a list of <code>Authentication</code> instances, based on the <code>authentication_classes</code> set on the view or based on the <code>DEFAULT_AUTHENTICATORS</code> setting.</p>
|
||||
<p>You won't typically need to access this property.</p>
|
||||
|
|
@ -522,22 +526,21 @@
|
|||
<h2 id="method">.method</h2>
|
||||
<p><code>request.method</code> returns the <strong>uppercased</strong> string representation of the request's HTTP method.</p>
|
||||
<p>Browser-based <code>PUT</code>, <code>PATCH</code> and <code>DELETE</code> forms are transparently supported.</p>
|
||||
<p>For more information see the <a href="../../topics/browser-enhancements">browser enhancements documentation</a>.</p>
|
||||
<p>For more information see the <a href="../../topics/browser-enhancements/">browser enhancements documentation</a>.</p>
|
||||
<h2 id="content_type">.content_type</h2>
|
||||
<p><code>request.content_type</code>, returns a string object representing the media type of the HTTP request's body, or an empty string if no media type was provided.</p>
|
||||
<p>You won't typically need to directly access the request's content type, as you'll normally rely on REST framework's default request parsing behavior.</p>
|
||||
<p>If you do need to access the content type of the request you should use the <code>.content_type</code> property in preference to using <code>request.META.get('HTTP_CONTENT_TYPE')</code>, as it provides transparent support for browser-based non-form content.</p>
|
||||
<p>For more information see the <a href="../../topics/browser-enhancements">browser enhancements documentation</a>.</p>
|
||||
<p>For more information see the <a href="../../topics/browser-enhancements/">browser enhancements documentation</a>.</p>
|
||||
<h2 id="stream">.stream</h2>
|
||||
<p><code>request.stream</code> returns a stream representing the content of the request body.</p>
|
||||
<p>You won't typically need to directly access the request's content, as you'll normally rely on REST framework's default request parsing behavior.</p>
|
||||
<p>If you do need to access the raw content directly, you should use the <code>.stream</code> property in preference to using <code>request.content</code>, as it provides transparent support for browser-based non-form content.</p>
|
||||
<p>For more information see the <a href="../../topics/browser-enhancements">browser enhancements documentation</a>.</p>
|
||||
<p>For more information see the <a href="../../topics/browser-enhancements/">browser enhancements documentation</a>.</p>
|
||||
<hr />
|
||||
<h1 id="standard-httprequest-attributes">Standard HttpRequest attributes</h1>
|
||||
<p>As REST framework's <code>Request</code> extends Django's <code>HttpRequest</code>, all the other standard attributes and methods are also available. For example the <code>request.META</code> and <code>request.session</code> dictionaries are available as normal.</p>
|
||||
<p>Note that due to implementation reasons the <code>Request</code> class does not inherit from <code>HttpRequest</code> class, but instead extends the class using composition.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Responses - Django REST framework</title>
|
||||
<title>Responses</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/responses/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../views">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../views/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../requests">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../requests/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Responses</a>
|
||||
<a href="./">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -447,7 +451,7 @@
|
|||
<p>Arguments:</p>
|
||||
<ul>
|
||||
<li><code>data</code>: The serialized data for the response.</li>
|
||||
<li><code>status</code>: A status code for the response. Defaults to 200. See also <a href="../status-codes">status codes</a>.</li>
|
||||
<li><code>status</code>: A status code for the response. Defaults to 200. See also <a href="../status-codes/">status codes</a>.</li>
|
||||
<li><code>template_name</code>: A template name to use if <code>HTMLRenderer</code> is selected.</li>
|
||||
<li><code>headers</code>: A dictionary of HTTP headers to use in the response.</li>
|
||||
<li><code>content_type</code>: The content type of the response. Typically, this will be set automatically by the renderer as determined by content negotiation, but there may be some cases where you need to specify the content type explicitly.</li>
|
||||
|
|
@ -481,7 +485,6 @@ response['Cache-Control'] = 'no-cache'
|
|||
<p><strong>Signature:</strong> <code>.render()</code></p>
|
||||
<p>As with any other <code>TemplateResponse</code>, this method is called to render the serialized data of the response into the final response content. When <code>.render()</code> is called, the response content will be set to the result of calling the <code>.render(data, accepted_media_type, renderer_context)</code> method on the <code>accepted_renderer</code> instance.</p>
|
||||
<p>You won't typically need to call <code>.render()</code> yourself, as it's handled by Django's standard response cycle.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Returning URLs - Django REST framework</title>
|
||||
<title>Returning URLs</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/reverse/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../exceptions">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../exceptions/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../format-suffixes">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../format-suffixes/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Returning URLs</a>
|
||||
<a href="./">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -414,7 +418,6 @@ class APIRootView(APIView):
|
|||
<p>As with the <code>reverse</code> function, you should <strong>include the request as a keyword argument</strong> to the function, for example:</p>
|
||||
<pre><code>api_root = reverse_lazy('api-root', request=request)
|
||||
</code></pre>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Routers - Django REST framework</title>
|
||||
<title>Routers</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/routers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../parsers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../parsers/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../viewsets">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../viewsets/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Routers</a>
|
||||
<a href="./">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -402,7 +406,7 @@
|
|||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#wqdb">wq.db</a>
|
||||
<a href="#modelrouter-wqdbrest">ModelRouter (wq.db.rest)</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
|
@ -526,7 +530,7 @@ class UserViewSet(ModelViewSet):
|
|||
<ul>
|
||||
<li>URL pattern: <code>^users/{pk}/change-password/$</code> Name: <code>'user-change-password'</code></li>
|
||||
</ul>
|
||||
<p>For more information see the viewset documentation on <a href="../viewsets#marking-extra-actions-for-routing">marking extra actions for routing</a>.</p>
|
||||
<p>For more information see the viewset documentation on <a href="../viewsets/#marking-extra-actions-for-routing">marking extra actions for routing</a>.</p>
|
||||
<h1 id="api-guide">API Guide</h1>
|
||||
<h2 id="simplerouter">SimpleRouter</h2>
|
||||
<p>This router includes routes for the standard set of <code>list</code>, <code>create</code>, <code>retrieve</code>, <code>update</code>, <code>partial_update</code> and <code>destroy</code> actions. The viewset can also mark additional methods to be routed, using the <code>@detail_route</code> or <code>@list_route</code> decorators.</p>
|
||||
|
|
@ -662,16 +666,15 @@ urlpatterns = router.urls
|
|||
<p>The following third party packages are also available.</p>
|
||||
<h2 id="drf-nested-routers">DRF Nested Routers</h2>
|
||||
<p>The <a href="https://github.com/alanjds/drf-nested-routers">drf-nested-routers package</a> provides routers and relationship fields for working with nested resources.</p>
|
||||
<h2 id="wqdb">wq.db</h2>
|
||||
<p>The <a href="http://wq.io/wq.db">wq.db package</a> provides an advanced <a href="http://wq.io/docs/app.py">Router</a> class (and singleton instance) that extends <code>DefaultRouter</code> with a <code>register_model()</code> API. Much like Django's <code>admin.site.register</code>, the only required argument to <code>app.router.register_model</code> is a model class. Reasonable defaults for a url prefix and viewset will be inferred from the model and global configuration.</p>
|
||||
<pre><code>from wq.db.rest import app
|
||||
<h2 id="modelrouter-wqdbrest">ModelRouter (wq.db.rest)</h2>
|
||||
<p>The <a href="http://wq.io/wq.db">wq.db package</a> provides an advanced <a href="http://wq.io/docs/router">ModelRouter</a> class (and singleton instance) that extends <code>DefaultRouter</code> with a <code>register_model()</code> API. Much like Django's <code>admin.site.register</code>, the only required argument to <code>rest.router.register_model</code> is a model class. Reasonable defaults for a url prefix, serializer, and viewset will be inferred from the model and global configuration.</p>
|
||||
<pre><code>from wq.db import rest
|
||||
from myapp.models import MyModel
|
||||
|
||||
app.router.register_model(MyModel)
|
||||
rest.router.register_model(MyModel)
|
||||
</code></pre>
|
||||
<h2 id="drf-extensions">DRF-extensions</h2>
|
||||
<p>The <a href="http://chibisov.github.io/drf-extensions/docs/"><code>DRF-extensions</code> package</a> provides <a href="http://chibisov.github.io/drf-extensions/docs/#routers">routers</a> for creating <a href="http://chibisov.github.io/drf-extensions/docs/#nested-routes">nested viewsets</a>, <a href="http://chibisov.github.io/drf-extensions/docs/#collection-level-controllers">collection level controllers</a> with <a href="http://chibisov.github.io/drf-extensions/docs/#controller-endpoint-name">customizable endpoint names</a>.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Serializers - Django REST framework</title>
|
||||
<title>Serializers</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/serializers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../fields">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../fields/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../renderers">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../renderers/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Serializers</a>
|
||||
<a href="./">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -742,7 +746,7 @@ class GameRecord(serializers.Serializer):
|
|||
fields=['room_number', 'date']
|
||||
)
|
||||
</code></pre>
|
||||
<p>For more information see the <a href="../validators">validators documentation</a>.</p>
|
||||
<p>For more information see the <a href="../validators/">validators documentation</a>.</p>
|
||||
<h2 id="accessing-the-initial-data-and-instance">Accessing the initial data and instance</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>
|
||||
|
|
@ -833,7 +837,7 @@ serializer.errors
|
|||
|
||||
return instance
|
||||
</code></pre>
|
||||
<p>Because the behavior of nested creates and updates can be ambiguous, and may require complex dependancies between related models, REST framework 3 requires you to always write these methods explicitly. The default <code>ModelSerializer</code> <code>.create()</code> and <code>.update()</code> methods do not include support for writable nested representations.</p>
|
||||
<p>Because the behavior of nested creates and updates can be ambiguous, and may require complex dependencies between related models, REST framework 3 requires you to always write these methods explicitly. The default <code>ModelSerializer</code> <code>.create()</code> and <code>.update()</code> methods do not include support for writable nested representations.</p>
|
||||
<p>It is possible that a third party package, providing automatic support some kinds of automatic writable nested representations may be released alongside the 3.1 release.</p>
|
||||
<h4 id="handling-saving-related-instances-in-model-manager-classes">Handling saving related instances in model manager classes</h4>
|
||||
<p>An alternative to saving multiple related instances in the serializer is to write custom model manager classes handle creating the correct instances.</p>
|
||||
|
|
@ -861,7 +865,7 @@ serializer.errors
|
|||
has_support_contract=validated_data['profile']['has_support_contract']
|
||||
)
|
||||
</code></pre>
|
||||
<p>For more details on this approach see the Django documentation on <a href="../../model-managers">model managers</a>, and <a href="../../encapsulation-blogpost">this blogpost on using model and manager classes</a>.</p>
|
||||
<p>For more details on this approach see the Django documentation on <a href="../model-managers">model managers</a>, and <a href="../encapsulation-blogpost">this blogpost on using model and manager classes</a>.</p>
|
||||
<h2 id="dealing-with-multiple-objects">Dealing with multiple objects</h2>
|
||||
<p>The <code>Serializer</code> class can also handle serializing or deserializing lists of objects.</p>
|
||||
<h4 id="serializing-multiple-objects">Serializing multiple objects</h4>
|
||||
|
|
@ -932,7 +936,7 @@ AccountSerializer():
|
|||
depth = 1
|
||||
</code></pre>
|
||||
<p>The <code>depth</code> option should be set to an integer value that indicates the depth of relationships that should be traversed before reverting to a flat representation.</p>
|
||||
<p>If you want to customize the way the serialization is done (e.g. using <code>allow_add_remove</code>) you'll need to define the field yourself.</p>
|
||||
<p>If you want to customize the way the serialization is done you'll need to define the field yourself.</p>
|
||||
<h2 id="specifying-fields-explicitly">Specifying fields explicitly</h2>
|
||||
<p>You can add extra fields to a <code>ModelSerializer</code> or override the default fields by declaring fields on the class, just as you would for a <code>Serializer</code> class.</p>
|
||||
<pre><code>class AccountSerializer(serializers.ModelSerializer):
|
||||
|
|
@ -959,7 +963,7 @@ AccountSerializer():
|
|||
<p>One example of this is a read-only relation to the currently authenticated <code>User</code> which is <code>unique_together</code> with another identifier. In this case you would declare the user field like so:</p>
|
||||
<pre><code>user = serializers.PrimaryKeyRelatedField(read_only=True, default=serializers.CurrentUserDefault())
|
||||
</code></pre>
|
||||
<p>Please review the <a href="../..//api-guide/validators/">Validators Documentation</a> for details on the <a href="../..//api-guide/validators/#uniquetogethervalidator">UniqueTogetherValidator</a> and <a href="../..//api-guide/validators/#currentuserdefault">CurrentUserDefault</a> classes.</p>
|
||||
<p>Please review the <a href="../../api-guide/validators/">Validators Documentation</a> for details on the <a href="../../api-guide/validators/#uniquetogethervalidator">UniqueTogetherValidator</a> and <a href="../../api-guide/validators/#currentuserdefault">CurrentUserDefault</a> classes.</p>
|
||||
<hr />
|
||||
<h2 id="additional-keyword-arguments">Additional keyword arguments</h2>
|
||||
<p>There is also a shortcut allowing you to specify arbitrary additional keyword arguments on fields, using the <code>extra_kwargs</code> option. Similarly to <code>read_only_fields</code> this means you do not need to explicitly declare the field on the serializer.</p>
|
||||
|
|
@ -982,7 +986,7 @@ AccountSerializer():
|
|||
<h2 id="relational-fields">Relational fields</h2>
|
||||
<p>When serializing model instances, there are a number of different ways you might choose to represent relationships. The default representation for <code>ModelSerializer</code> is to use the primary keys of the related instances.</p>
|
||||
<p>Alternative representations include serializing using hyperlinks, serializing complete nested representations, or serializing with a custom representation.</p>
|
||||
<p>For full details see the <a href="../relations">serializer relations</a> documentation.</p>
|
||||
<p>For full details see the <a href="../relations/">serializer relations</a> documentation.</p>
|
||||
<h2 id="inheritance-of-the-meta-class">Inheritance of the 'Meta' class</h2>
|
||||
<p>The inner <code>Meta</code> class on serializers is not inherited from parent classes by default. This is the same behavior as with Django's <code>Model</code> and <code>ModelForm</code> classes. If you want the <code>Meta</code> class to inherit from a parent class you must do so explicitly. For example:</p>
|
||||
<pre><code>class AccountSerializer(MyBaseSerializer):
|
||||
|
|
@ -1169,7 +1173,7 @@ class BookSerializer(serializers.Serializer):
|
|||
<ul>
|
||||
<li><code>.to_representation()</code> - Override this to support serialization, for read operations.</li>
|
||||
<li><code>.to_internal_value()</code> - Override this to support deserialization, for write operations.</li>
|
||||
<li><code>.create()</code> and <code>.update()</code> - Overide either or both of these to support saving instances.</li>
|
||||
<li><code>.create()</code> and <code>.update()</code> - Override either or both of these to support saving instances.</li>
|
||||
</ul>
|
||||
<p>Because this class provides the same interface as the <code>Serializer</code> class, you can use it with the existing generic class based views exactly as you would for a regular <code>Serializer</code> or <code>ModelSerializer</code>.</p>
|
||||
<p>The only difference you'll notice when doing so is the <code>BaseSerializer</code> classes will not generate HTML forms in the browsable API. This is because the data they return does not include all the field information that would allow each field to be rendered into a suitable HTML input.</p>
|
||||
|
|
@ -1345,7 +1349,6 @@ def all_high_scores(request):
|
|||
<p>The <a href="https://github.com/djangonauts/django-rest-framework-gis">django-rest-framework-gis</a> package provides a <code>GeoFeatureModelSerializer</code> serializer class that supports GeoJSON both for read and write operations.</p>
|
||||
<h2 id="hstoreserializer">HStoreSerializer</h2>
|
||||
<p>The <a href="https://github.com/djangonauts/django-rest-framework-hstore">django-rest-framework-hstore</a> package provides an <code>HStoreSerializer</code> to support <a href="https://github.com/djangonauts/django-hstore">django-hstore</a> <code>DictionaryField</code> model field and its <code>schema-mode</code> feature.</p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Settings - Django REST framework</title>
|
||||
<title>Settings</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/settings/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../../topics/documenting-your-api">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../../topics/documenting-your-api/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../testing">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../testing/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Settings</a>
|
||||
<a href="./">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -686,7 +690,6 @@ If set to <code>None</code> then generic filtering is disabled.</p>
|
|||
<h4 id="num_proxies">NUM_PROXIES</h4>
|
||||
<p>An integer of 0 or more, that may be used to specify the number of application proxies that the API runs behind. This allows throttling to more accurately identify client IP addresses. If set to <code>None</code> then less strict IP matching will be used by the throttle classes.</p>
|
||||
<p>Default: <code>None</code></p>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Status codes - Django REST framework</title>
|
||||
<title>Status codes</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/status-codes/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../testing">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../testing/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../exceptions">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../exceptions/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Status codes</a>
|
||||
<a href="./">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing">Testing</a>
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -486,7 +490,6 @@ is_redirect() # 3xx
|
|||
is_client_error() # 4xx
|
||||
is_server_error() # 5xx
|
||||
</code></pre>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Testing - Django REST framework</title>
|
||||
<title>Testing</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/testing/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../settings">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../settings/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../status-codes">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../status-codes/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers">Serializers</a>
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields">Serializer fields</a>
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations">Serializer relations</a>
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators">Validators</a>
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication">Authentication</a>
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions">Permissions</a>
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling">Throttling</a>
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering">Filtering</a>
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination">Pagination</a>
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning">Versioning</a>
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation">Content negotiation</a>
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata">Metadata</a>
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes">Format suffixes</a>
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse">Returning URLs</a>
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions">Exceptions</a>
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes">Status codes</a>
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href=".">Testing</a>
|
||||
<a href="./">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings">Settings</a>
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -232,55 +236,55 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements">Browser enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-resources">Third Party Resources</a>
|
||||
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing">Contributing to REST framework</a>
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management">Project management</a>
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement">3.0 Announcement</a>
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement">3.1 Announcement</a>
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement">Kickstarter Announcement</a>
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes">Release Notes</a>
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -650,7 +654,6 @@ self.assertEqual(response.content, '{"username": "lauren", "id": 4}')
|
|||
)
|
||||
}
|
||||
</code></pre>
|
||||
|
||||
</div>
|
||||
<!--/span-->
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Throttling - Django REST framework</title>
|
||||
<title>Throttling</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/throttling/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
|
|
@ -62,10 +62,10 @@
|
|||
<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 " rel="prev" href="../filtering">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../filtering/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../permissions">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../permissions/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small" href="#searchModal" data-toggle="modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -81,36 +81,40 @@
|
|||
<ul class="nav navbar-nav">
|
||||
<li ><a href="/">Home</a></li>
|
||||
|
||||
<li >
|
||||
<a href="../..">Home</a>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/quickstart">Quickstart</a>
|
||||
<a href="../../tutorial/quickstart/">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization">1 - Serialization</a>
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/2-requests-and-responses">2 - Requests and responses</a>
|
||||
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/3-class-based-views">3 - Class based views</a>
|
||||
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/4-authentication-and-permissions">4 - Authentication and permissions</a>
|
||||
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis">5 - Relationships and hyperlinked APIs</a>
|
||||
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers">6 - Viewsets and routers</a>
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -121,107 +125,107 @@
|
|||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests">Requests</a>
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses">Responses</a>
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views">Views</a>
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views">Generic views</a>
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets">Viewsets</a>
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers">Routers</a>
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers">Parsers</a>
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers">Renderers</a>
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||