mirror of
https://github.com/encode/django-rest-framework.git
synced 2026-01-12 19:45:59 +03:00
Deployed 1c3f7962 with MkDocs version: 0.16.3
This commit is contained in:
parent
8e48be4343
commit
27743fc266
51
404.html
51
404.html
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="/api-guide/permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/api-guide/caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/api-guide/throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="/topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="/topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="/community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="/community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="/community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/project-management/">Project management</a>
|
||||
<a href="/community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/jobs/">Jobs</a>
|
||||
<a href="/community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="/community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="/community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="/community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="/community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="/community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="/community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="/community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="/community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="/community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="/community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="/community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/funding/">Funding</a>
|
||||
<a href="/community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="/topics/release-notes/">Release Notes</a>
|
||||
<a href="/community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -400,7 +411,7 @@
|
|||
|
||||
<h1 id="404-page-not-found" style="text-align: center">404</h1>
|
||||
<p style="text-align: center"><strong>Page not found</strong></p>
|
||||
<p style="text-align: center">Try the <a href="http://www.django-rest-framework.org/">homepage</a>, or <a href="#searchModal" data-toggle="modal">search the documentation</a>.</p>
|
||||
<p style="text-align: center">Try the <a href="https://www.django-rest-framework.org/">homepage</a>, or <a href="#searchModal" data-toggle="modal">search the documentation</a>.</p>
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Authentication - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/authentication/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Authentication">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -456,10 +467,6 @@
|
|||
<a href="#digest-authentication">Digest Authentication</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#django-oauth2-consumer">Django OAuth2 Consumer</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#json-web-token-authentication">JSON Web Token Authentication</a>
|
||||
</li>
|
||||
|
|
@ -801,14 +808,12 @@ REST_FRAMEWORK = {
|
|||
<p>For details on configuration and usage see the Django REST framework OAuth documentation for <a href="https://jpadilla.github.io/django-rest-framework-oauth/authentication/">authentication</a> and <a href="https://jpadilla.github.io/django-rest-framework-oauth/permissions/">permissions</a>.</p>
|
||||
<h2 id="digest-authentication"><a class="toclink" href="#digest-authentication">Digest Authentication</a></h2>
|
||||
<p>HTTP digest authentication is a widely implemented scheme that was intended to replace HTTP basic authentication, and which provides a simple encrypted authentication mechanism. <a href="https://github.com/juanriaza">Juan Riaza</a> maintains the <a href="https://github.com/juanriaza/django-rest-framework-digestauth">djangorestframework-digestauth</a> package which provides HTTP digest authentication support for REST framework.</p>
|
||||
<h2 id="django-oauth2-consumer"><a class="toclink" href="#django-oauth2-consumer">Django OAuth2 Consumer</a></h2>
|
||||
<p>The <a href="https://github.com/Rediker-Software/doac">Django OAuth2 Consumer</a> library from <a href="https://github.com/Rediker-Software">Rediker Software</a> is another package that provides <a href="https://github.com/Rediker-Software/doac/blob/master/docs/integrations.md#">OAuth 2.0 support for REST framework</a>. The package includes token scoping permissions on tokens, which allows finer-grained access to your API.</p>
|
||||
<h2 id="json-web-token-authentication"><a class="toclink" href="#json-web-token-authentication">JSON Web Token Authentication</a></h2>
|
||||
<p>JSON Web Token is a fairly new standard which can be used for token-based authentication. Unlike the built-in TokenAuthentication scheme, JWT Authentication doesn't need to use a database to validate a token. <a href="https://github.com/GetBlimp">Blimp</a> maintains the <a href="https://github.com/GetBlimp/django-rest-framework-jwt">djangorestframework-jwt</a> package which provides a JWT Authentication class as well as a mechanism for clients to obtain a JWT given the username and password. An alternative package for JWT authentication is <a href="https://github.com/davesque/django-rest-framework-simplejwt">djangorestframework-simplejwt</a> which provides different features as well as a pluggable token blacklist app.</p>
|
||||
<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 package for JWT authentication is <a href="https://github.com/davesque/django-rest-framework-simplejwt">djangorestframework-simplejwt</a> which provides some features as well as a pluggable token blacklist app.</p>
|
||||
<h2 id="hawk-http-authentication"><a class="toclink" href="#hawk-http-authentication">Hawk HTTP Authentication</a></h2>
|
||||
<p>The <a href="https://hawkrest.readthedocs.io/en/latest/">HawkREST</a> library builds on the <a href="https://mohawk.readthedocs.io/en/latest/">Mohawk</a> library to let you work with <a href="https://github.com/hueniverse/hawk">Hawk</a> signed requests and responses in your API. <a href="https://github.com/hueniverse/hawk">Hawk</a> lets two parties securely communicate with each other using messages signed by a shared key. It is based on <a href="https://tools.ietf.org/html/draft-hammer-oauth-v2-mac-token-05">HTTP MAC access authentication</a> (which was based on parts of <a href="https://oauth.net/core/1.0a/">OAuth 1.0</a>).</p>
|
||||
<h2 id="http-signature-authentication"><a class="toclink" href="#http-signature-authentication">HTTP Signature Authentication</a></h2>
|
||||
<p>HTTP Signature (currently a <a href="https://datatracker.ietf.org/doc/draft-cavage-http-signatures/">IETF draft</a>) provides a way to achieve origin authentication and message integrity for HTTP messages. Similar to <a href="https://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>
|
||||
<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="https://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> (outdated) package which provides an easy to use HTTP Signature Authentication mechanism. You can use the updated fork version of <a href="https://github.com/etoccalino/django-rest-framework-httpsignature">djangorestframework-httpsignature</a>, which is <a href="https://github.com/ahknight/drf-httpsig">drf-httpsig</a>.</p>
|
||||
<h2 id="djoser"><a class="toclink" href="#djoser">Djoser</a></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"><a class="toclink" href="#django-rest-auth">django-rest-auth</a></h2>
|
||||
|
|
|
|||
514
api-guide/caching/index.html
Normal file
514
api-guide/caching/index.html
Normal file
|
|
@ -0,0 +1,514 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<meta charset="utf-8">
|
||||
<title>Caching - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/caching/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Caching">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
||||
<!-- Le styles -->
|
||||
<link href="../../css/prettify.css" rel="stylesheet">
|
||||
<link href="../../css/bootstrap.css" rel="stylesheet">
|
||||
<link href="../../css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="../../css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
|
||||
<![endif]-->
|
||||
|
||||
<script type="text/javascript">
|
||||
var _gaq = _gaq || [];
|
||||
_gaq.push(['_setAccount', 'UA-18852272-2']);
|
||||
_gaq.push(['_trackPageview']);
|
||||
|
||||
(function() {
|
||||
var ga = document.createElement('script');
|
||||
ga.type = 'text/javascript';
|
||||
ga.async = true;
|
||||
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
||||
var s = document.getElementsByTagName('script')[0];
|
||||
s.parentNode.insertBefore(ga, s);
|
||||
})();
|
||||
</script>
|
||||
|
||||
<style>
|
||||
#sidebarInclude img {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
#sidebarInclude a.promo {
|
||||
color: black;
|
||||
}
|
||||
@media (max-width: 767px) {
|
||||
div.promo {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body onload="prettyPrint()" class="-page">
|
||||
|
||||
<div class="wrapper">
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/encode/django-rest-framework/tree/master">GitHub</a>
|
||||
<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="../permissions/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
<ul class="nav navbar-nav">
|
||||
|
||||
<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>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<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>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<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>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../tutorial/7-schemas-and-client-libraries/">7 - Schemas and client libraries</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">API Guide <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../requests/">Requests</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../responses/">Responses</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../views/">Views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../generic-views/">Generic views</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../viewsets/">Viewsets</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../routers/">Routers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../parsers/">Parsers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../renderers/">Renderers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../serializers/">Serializers</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../fields/">Serializer fields</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../relations/">Serializer relations</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../validators/">Validators</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../authentication/">Authentication</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../filtering/">Filtering</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../pagination/">Pagination</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../versioning/">Versioning</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../content-negotiation/">Content negotiation</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../metadata/">Metadata</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../schemas/">Schemas</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../format-suffixes/">Format suffixes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../reverse/">Returning URLs</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../exceptions/">Exceptions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../status-codes/">Status codes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../testing/">Testing</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../settings/">Settings</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/api-clients/">API Clients</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/html-and-forms/">HTML & Forms</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browser-enhancements/">Browser Enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
<!--/.nav-collapse -->
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="body-content">
|
||||
<div class="container-fluid">
|
||||
<!-- Search Modal -->
|
||||
<div id="mkdocs_search_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
||||
<h3 id="myModalLabel">Documentation search</h3>
|
||||
</div>
|
||||
|
||||
<div class="modal-body">
|
||||
<form role="form" autocomplete="off">
|
||||
<div class="form-group">
|
||||
<input type="text" name="q" class="form-control" placeholder="Search..." id="mkdocs-search-query">
|
||||
</div>
|
||||
</form>
|
||||
<div id="mkdocs-search-results"></div>
|
||||
</div>
|
||||
|
||||
<div class="modal-footer">
|
||||
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span3">
|
||||
<div id="table-of-contents">
|
||||
<ul class="nav nav-list side-nav well sidebar-nav-fixed">
|
||||
|
||||
|
||||
|
||||
<li class="main">
|
||||
<a href="#caching">Caching</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li>
|
||||
<a href="#using-cache-with-apiview-and-viewsets">Using cache with apiview and viewsets</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
||||
<div class="promo">
|
||||
<hr/>
|
||||
<div id="sidebarInclude">
|
||||
</div>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="main-content" class="span9">
|
||||
|
||||
|
||||
|
||||
<h1 id="caching"><a class="toclink" href="#caching">Caching</a></h1>
|
||||
<blockquote>
|
||||
<p>A certain woman had a very sharp conciousness but almost no
|
||||
memory ... She remembered enough to work, and she worked hard.
|
||||
- Lydia Davis</p>
|
||||
</blockquote>
|
||||
<p>Caching in REST Framework works well with the cache utilities
|
||||
provided in Django.</p>
|
||||
<hr />
|
||||
<h2 id="using-cache-with-apiview-and-viewsets"><a class="toclink" href="#using-cache-with-apiview-and-viewsets">Using cache with apiview and viewsets</a></h2>
|
||||
<p>Django provides a <a href="https://docs.djangoproject.com/en/dev/topics/class-based-views/intro/#decorating-the-class"><code>method_decorator</code></a> to use
|
||||
decorators with class based views. This can be used with
|
||||
with other cache decorators such as <a href="https://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache"><code>cache_page</code></a> and
|
||||
<a href="https://docs.djangoproject.com/en/dev/topics/http/decorators/#django.views.decorators.vary.vary_on_cookie"><code>vary_on_cookie</code></a>.</p>
|
||||
<pre><code class="python">from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework import viewsets
|
||||
|
||||
class UserViewSet(viewsets.Viewset):
|
||||
|
||||
# Cache requested url for each user for 2 hours
|
||||
@method_decorator(cache_page(60*60*2))
|
||||
@method_decorator(vary_on_cookie)
|
||||
def list(self, request, format=None):
|
||||
content = {
|
||||
'user_feed': request.user.get_user_feed()
|
||||
}
|
||||
return Response(content)
|
||||
|
||||
class PostView(APIView):
|
||||
|
||||
# Cache page for the requested url
|
||||
@method_decorator(cache_page(60*60*2))
|
||||
def get(self, request, format=None):
|
||||
content = {
|
||||
'title': 'Post title',
|
||||
'body': 'Post content'
|
||||
}
|
||||
return Response(content)
|
||||
</code></pre>
|
||||
|
||||
<p><strong>NOTE:</strong> The <a href="https://docs.djangoproject.com/en/dev/topics/cache/#the-per-view-cache"><code>cache_page</code></a> decorator only caches the
|
||||
<code>GET</code> and <code>HEAD</code> responses with status 200.</p>
|
||||
|
||||
|
||||
</div> <!--/span-->
|
||||
</div> <!--/row-->
|
||||
</div> <!--/.fluid-container-->
|
||||
</div> <!--/.body content-->
|
||||
<div id="push"></div>
|
||||
</div> <!--/.wrapper -->
|
||||
|
||||
<footer class="span12">
|
||||
<p>Documentation built with <a href="http://www.mkdocs.org/">MkDocs</a>.
|
||||
</p>
|
||||
</footer>
|
||||
|
||||
<!-- Le javascript
|
||||
================================================== -->
|
||||
<!-- Placed at the end of the document so the pages load faster -->
|
||||
<script src="../../js/jquery-1.8.1-min.js"></script>
|
||||
<script src="../../js/prettify-1.0.js"></script>
|
||||
<script src="../../js/bootstrap-2.1.1-min.js"></script>
|
||||
<script src="https://fund.django-rest-framework.org/sidebar_include.js"></script>
|
||||
<script>var base_url = '../..';</script>
|
||||
<script src="../../mkdocs/js/require.js"></script>
|
||||
<script src="../../js/theme.js"></script>
|
||||
|
||||
<script>
|
||||
var shiftWindow = function() {
|
||||
scrollBy(0, -50)
|
||||
};
|
||||
|
||||
if (location.hash) shiftWindow();
|
||||
window.addEventListener("hashchange", shiftWindow);
|
||||
|
||||
$('.dropdown-menu').on('click touchstart', function(event) {
|
||||
event.stopPropagation();
|
||||
});
|
||||
|
||||
// Dynamically force sidenav/dropdown to no higher than browser window
|
||||
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
|
||||
|
||||
$(function() {
|
||||
$(window).resize(function() {
|
||||
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Content negotiation - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/content-negotiation/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Content negotiation">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Exceptions - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/exceptions/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Exceptions">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -459,7 +470,7 @@
|
|||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#rest_frameworkexceptionsserver_error_1">rest_framework.exceptions.server_error</a>
|
||||
<a href="#rest_frameworkexceptionsbad_request">rest_framework.exceptions.bad_request</a>
|
||||
</li>
|
||||
|
||||
|
||||
|
|
@ -654,7 +665,7 @@ API-only application.)</p>
|
|||
<p>Set as <code>handler500</code>:</p>
|
||||
<pre><code>handler500 = 'rest_framework.exceptions.server_error'
|
||||
</code></pre>
|
||||
<h2 id="rest_frameworkexceptionsserver_error_1"><a class="toclink" href="#rest_frameworkexceptionsserver_error_1"><code>rest_framework.exceptions.server_error</code></a></h2>
|
||||
<h2 id="rest_frameworkexceptionsbad_request"><a class="toclink" href="#rest_frameworkexceptionsbad_request"><code>rest_framework.exceptions.bad_request</code></a></h2>
|
||||
<p>Returns a response with status code <code>400</code> and <code>application/json</code> content type.</p>
|
||||
<p>Set as <code>handler400</code>:</p>
|
||||
<pre><code>handler400 = 'rest_framework.exceptions.bad_request'
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Serializer fields - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/fields/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Serializer fields">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -817,7 +828,7 @@ color_channel = serializers.ChoiceField(
|
|||
<h4 id="datetimefield-format-strings"><a class="toclink" href="#datetimefield-format-strings"><code>DateTimeField</code> format strings.</a></h4>
|
||||
<p>Format strings may either be <a href="https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior">Python strftime formats</a> which explicitly specify the format, or the special string <code>'iso-8601'</code>, which indicates that <a href="https://www.w3.org/TR/NOTE-datetime">ISO 8601</a> style datetimes should be used. (eg <code>'2013-01-29T12:34:56.000000Z'</code>)</p>
|
||||
<p>When a value of <code>None</code> is used for the format <code>datetime</code> objects will be returned by <code>to_representation</code> and the final output representation will determined by the renderer class.</p>
|
||||
<h4 id="auto_now-and-auto_now_add-model-fields"><code>auto_now_add</code> model fields.<a class="toclink" href="#auto_now-and-auto_now_add-model-fields"><code>auto_now</code> and </a></h4>
|
||||
<h4 id="auto_now-and-auto_now_add-model-fields"><a class="toclink" href="#auto_now-and-auto_now_add-model-fields"><code>auto_now</code> and <code>auto_now_add</code> model fields.</a></h4>
|
||||
<p>When using <code>ModelSerializer</code> or <code>HyperlinkedModelSerializer</code>, note that any model fields with <code>auto_now=True</code> or <code>auto_now_add=True</code> will use serializer fields that are <code>read_only=True</code> by default.</p>
|
||||
<p>If you want to override this behavior, you'll need to declare the <code>DateTimeField</code> explicitly on the serializer. For example:</p>
|
||||
<pre><code>class CommentSerializer(serializers.ModelSerializer):
|
||||
|
|
@ -851,7 +862,11 @@ color_channel = serializers.ChoiceField(
|
|||
Corresponds to <code>django.db.models.fields.DurationField</code></p>
|
||||
<p>The <code>validated_data</code> for these fields will contain a <code>datetime.timedelta</code> instance.
|
||||
The representation is a string following this format <code>'[DD] [HH:[MM:]]ss[.uuuuuu]'</code>.</p>
|
||||
<p><strong>Signature:</strong> <code>DurationField()</code></p>
|
||||
<p><strong>Signature:</strong> <code>DurationField(max_value=None, min_value=None)</code></p>
|
||||
<ul>
|
||||
<li><code>max_value</code> Validate that the duration provided is no greater than this value.</li>
|
||||
<li><code>min_value</code> Validate that the duration provided is no less than this value.</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h1 id="choice-selection-fields"><a class="toclink" href="#choice-selection-fields">Choice selection fields</a></h1>
|
||||
<h2 id="choicefield"><a class="toclink" href="#choicefield">ChoiceField</a></h2>
|
||||
|
|
@ -1012,8 +1027,8 @@ class ColorField(serializers.Field):
|
|||
"""
|
||||
Color objects are serialized into 'rgb(#, #, #)' notation.
|
||||
"""
|
||||
def to_representation(self, obj):
|
||||
return "rgb(%d, %d, %d)" % (obj.red, obj.green, obj.blue)
|
||||
def to_representation(self, value):
|
||||
return "rgb(%d, %d, %d)" % (value.red, value.green, value.blue)
|
||||
|
||||
def to_internal_value(self, data):
|
||||
data = data.strip('rgb(').rstrip(')')
|
||||
|
|
@ -1023,16 +1038,16 @@ class ColorField(serializers.Field):
|
|||
<p>By default field values are treated as mapping to an attribute on the object. If you need to customize how the field value is accessed and set you need to override <code>.get_attribute()</code> and/or <code>.get_value()</code>.</p>
|
||||
<p>As an example, let's create a field that can be used to represent the class name of the object being serialized:</p>
|
||||
<pre><code>class ClassNameField(serializers.Field):
|
||||
def get_attribute(self, obj):
|
||||
def get_attribute(self, instance):
|
||||
# We pass the object instance onto `to_representation`,
|
||||
# not just the field attribute.
|
||||
return obj
|
||||
return instance
|
||||
|
||||
def to_representation(self, obj):
|
||||
def to_representation(self, value):
|
||||
"""
|
||||
Serialize the object's class name.
|
||||
Serialize the value's class name.
|
||||
"""
|
||||
return obj.__class__.__name__
|
||||
return value.__class__.__name__
|
||||
</code></pre>
|
||||
<h3 id="raising-validation-errors"><a class="toclink" href="#raising-validation-errors">Raising validation errors</a></h3>
|
||||
<p>Our <code>ColorField</code> class above currently does not perform any data validation.
|
||||
|
|
@ -1087,10 +1102,10 @@ def to_internal_value(self, data):
|
|||
the coordinate pair:</p>
|
||||
<pre><code>class CoordinateField(serializers.Field):
|
||||
|
||||
def to_representation(self, obj):
|
||||
def to_representation(self, value):
|
||||
ret = {
|
||||
"x": obj.x_coordinate,
|
||||
"y": obj.y_coordinate
|
||||
"x": value.x_coordinate,
|
||||
"y": value.y_coordinate
|
||||
}
|
||||
return ret
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Filtering - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/filtering/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Filtering">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -645,7 +656,9 @@ It's also recommended that you read the section on <a href="https://django-filte
|
|||
<p>When in use, the browsable API will include a <code>SearchFilter</code> control:</p>
|
||||
<p><img alt="Search Filter" src="../../img/search-filter.png" /></p>
|
||||
<p>The <code>SearchFilter</code> class will only be applied if the view has a <code>search_fields</code> attribute set. The <code>search_fields</code> attribute should be a list of names of text type fields on the model, such as <code>CharField</code> or <code>TextField</code>.</p>
|
||||
<pre><code>class UserListView(generics.ListAPIView):
|
||||
<pre><code>from rest_framework import filters
|
||||
|
||||
class UserListView(generics.ListAPIView):
|
||||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
filter_backends = (filters.SearchFilter,)
|
||||
|
|
@ -715,6 +728,9 @@ It's also recommended that you read the section on <a href="https://django-filte
|
|||
<hr />
|
||||
<h2 id="djangoobjectpermissionsfilter"><a class="toclink" href="#djangoobjectpermissionsfilter">DjangoObjectPermissionsFilter</a></h2>
|
||||
<p>The <code>DjangoObjectPermissionsFilter</code> is intended to be used together with the <a href="https://django-guardian.readthedocs.io/"><code>django-guardian</code></a> package, with custom <code>'view'</code> permissions added. The filter will ensure that querysets only returns objects for which the user has the appropriate view permission.</p>
|
||||
<hr />
|
||||
<p><strong>Note:</strong> This filter has been deprecated as of version 3.9 and moved to the 3rd-party <a href="https://github.com/rpkilby/django-rest-framework-guardian"><code>djangorestframework-guardian</code> package</a>.</p>
|
||||
<hr />
|
||||
<p>If you're using <code>DjangoObjectPermissionsFilter</code>, you'll probably also want to add an appropriate object permissions class, to ensure that users can only operate on instances if they have the appropriate object permissions. The easiest way to do this is to subclass <code>DjangoObjectPermissions</code> and add <code>'view'</code> permissions to the <code>perms_map</code> attribute.</p>
|
||||
<p>A complete example using both <code>DjangoObjectPermissionsFilter</code> and <code>DjangoObjectPermissions</code> might look something like this.</p>
|
||||
<p><strong>permissions.py</strong>:</p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Format suffixes - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/format-suffixes/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Format suffixes">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -486,7 +497,7 @@ urlpatterns = i18n_patterns(
|
|||
<h2 id="accept-headers-vs-format-suffixes"><a class="toclink" href="#accept-headers-vs-format-suffixes">Accept headers vs. format suffixes</a></h2>
|
||||
<p>There seems to be a view among some of the Web community that filename extensions are not a RESTful pattern, and that <code>HTTP Accept</code> headers should always be used instead.</p>
|
||||
<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>“That's why I always prefer extensions. Neither choice has anything to do with REST.” — Roy Fielding, <a href="https://groups.yahoo.com/neo/groups/rest-discuss/conversations/topics/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>
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Generic views - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/generic-views/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Generic views">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Metadata - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/metadata/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Metadata">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -505,7 +516,7 @@ def schema(self, request):
|
|||
<hr />
|
||||
<h1 id="custom-metadata-classes"><a class="toclink" href="#custom-metadata-classes">Custom metadata classes</a></h1>
|
||||
<p>If you want to provide a custom metadata class you should override <code>BaseMetadata</code> and implement the <code>determine_metadata(self, request, view)</code> method.</p>
|
||||
<p>Useful things that you might want to do could include returning schema information, using a format such as <a href="http://json-schema.org/">JSON schema</a>, or returning debug information to admin users.</p>
|
||||
<p>Useful things that you might want to do could include returning schema information, using a format such as <a href="https://json-schema.org/">JSON schema</a>, or returning debug information to admin users.</p>
|
||||
<h2 id="example"><a class="toclink" href="#example">Example</a></h2>
|
||||
<p>The following class could be used to limit the information that is returned to <code>OPTIONS</code> requests.</p>
|
||||
<pre><code>class MinimalMetadata(BaseMetadata):
|
||||
|
|
@ -527,7 +538,7 @@ def schema(self, request):
|
|||
<h1 id="third-party-packages"><a class="toclink" href="#third-party-packages">Third party packages</a></h1>
|
||||
<p>The following third party packages provide additional metadata implementations.</p>
|
||||
<h2 id="drf-schema-adapter"><a class="toclink" href="#drf-schema-adapter">DRF-schema-adapter</a></h2>
|
||||
<p><a href="https://github.com/drf-forms/drf-schema-adapter">drf-schema-adapter</a> is a set of tools that makes it easier to provide schema information to frontend frameworks and libraries. It provides a metadata mixin as well as 2 metadata classes and several adapters suitable to generate <a href="http://json-schema.org/">json-schema</a> as well as schema information readable by various libraries.</p>
|
||||
<p><a href="https://github.com/drf-forms/drf-schema-adapter">drf-schema-adapter</a> is a set of tools that makes it easier to provide schema information to frontend frameworks and libraries. It provides a metadata mixin as well as 2 metadata classes and several adapters suitable to generate <a href="https://json-schema.org/">json-schema</a> as well as schema information readable by various libraries.</p>
|
||||
<p>You can also write your own adapter to work with your specific frontend.
|
||||
If you wish to do so, it also provides an exporter that can export those schema information to json files.</p>
|
||||
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Pagination - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/pagination/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Pagination">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -518,7 +529,7 @@ class StandardResultsSetPagination(PageNumberPagination):
|
|||
page_size_query_param = 'page_size'
|
||||
max_page_size = 1000
|
||||
</code></pre>
|
||||
<p>You can then apply your new style to a view using the <code>.pagination_class</code> attribute:</p>
|
||||
<p>You can then apply your new style to a view using the <code>pagination_class</code> attribute:</p>
|
||||
<pre><code>class BillingRecordsView(generics.ListAPIView):
|
||||
queryset = Billing.objects.all()
|
||||
serializer_class = BillingRecordsSerializer
|
||||
|
|
@ -627,7 +638,7 @@ class StandardResultsSetPagination(PageNumberPagination):
|
|||
<li>The field should have a database index.</li>
|
||||
</ul>
|
||||
<p>Using an ordering field that does not satisfy these constraints will generally still work, but you'll be losing some of the benefits of cursor pagination.</p>
|
||||
<p>For more technical details on the implementation we use for cursor pagination, the <a href="http://cramer.io/2011/03/08/building-cursors-for-the-disqus-api">"Building cursors for the Disqus API"</a> blog post gives a good overview of the basic approach.</p>
|
||||
<p>For more technical details on the implementation we use for cursor pagination, the <a href="https://cra.mr/2011/03/08/building-cursors-for-the-disqus-api">"Building cursors for the Disqus API"</a> blog post gives a good overview of the basic approach.</p>
|
||||
<h4 id="setup_2"><a class="toclink" href="#setup_2">Setup</a></h4>
|
||||
<p>To enable the <code>CursorPagination</code> style globally, use the following configuration, modifying the <code>PAGE_SIZE</code> as desired:</p>
|
||||
<pre><code>REST_FRAMEWORK = {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Parsers - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/parsers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Parsers">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Permissions - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/permissions/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Permissions">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -58,7 +58,7 @@
|
|||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/encode/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="../caching/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../authentication/">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="./">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -575,6 +586,25 @@ def example_view(request, format=None):
|
|||
return Response(content)
|
||||
</code></pre>
|
||||
<p><strong>Note:</strong> when you set new permission classes through class attribute or decorators you're telling the view to ignore the default list set over the <strong>settings.py</strong> file.</p>
|
||||
<p>Provided they inherit from <code>rest_framework.permissions.BasePermission</code>, permissions can be composed using standard Python bitwise operators. For example, <code>IsAuthenticatedOrReadOnly</code> could be written:</p>
|
||||
<pre><code>from rest_framework.permissions import BasePermission, IsAuthenticated
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
class ReadOnly(BasePermission):
|
||||
def has_permission(self, request, view):
|
||||
return request.method in SAFE_METHODS
|
||||
|
||||
class ExampleView(APIView):
|
||||
permission_classes = (IsAuthenticated|ReadOnly)
|
||||
|
||||
def get(self, request, format=None):
|
||||
content = {
|
||||
'status': 'request was permitted'
|
||||
}
|
||||
return Response(content)
|
||||
</code></pre>
|
||||
<p><strong>Note:</strong> it only supports & -and- and | -or-.</p>
|
||||
<hr />
|
||||
<h1 id="api-reference"><a class="toclink" href="#api-reference">API Reference</a></h1>
|
||||
<h2 id="allowany"><a class="toclink" href="#allowany">AllowAny</a></h2>
|
||||
|
|
@ -615,8 +645,7 @@ def example_view(request, format=None):
|
|||
<p>Note that <code>DjangoObjectPermissions</code> <strong>does not</strong> require the <code>django-guardian</code> package, and should support other object-level backends equally well.</p>
|
||||
<p>As with <code>DjangoModelPermissions</code> you can use custom model permissions by overriding <code>DjangoObjectPermissions</code> and setting the <code>.perms_map</code> property. Refer to the source code for details.</p>
|
||||
<hr />
|
||||
<p><strong>Note</strong>: If you need object level <code>view</code> permissions for <code>GET</code>, <code>HEAD</code> and <code>OPTIONS</code> requests, you'll want to consider also adding the <code>DjangoObjectPermissionsFilter</code> class to ensure that list endpoints only return results including objects for which the user has appropriate view permissions.</p>
|
||||
<hr />
|
||||
<p><strong>Note</strong>: If you need object level <code>view</code> permissions for <code>GET</code>, <code>HEAD</code> and <code>OPTIONS</code> requests and are using django-guardian for your object-level permissions backend, you'll want to consider using the <code>DjangoObjectPermissionsFilter</code> class provided by the <a href="https://github.com/rpkilby/django-rest-framework-guardian"><code>djangorestframework-guardian</code> package</a>. It ensures that list endpoints only return results including objects for which the user has appropriate view permissions.</p>
|
||||
<hr />
|
||||
<h1 id="custom-permissions"><a class="toclink" href="#custom-permissions">Custom permissions</a></h1>
|
||||
<p>To implement a custom permission, override <code>BasePermission</code> and implement either, or both, of the following methods:</p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Serializer relations - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/relations/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Serializer relations">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -650,7 +661,7 @@ class Track(models.Model):
|
|||
<hr />
|
||||
<p><strong>Arguments</strong>:</p>
|
||||
<ul>
|
||||
<li><code>view_name</code> - The view name that should be used as the target of the relationship. If you're using <a href="http://www.django-rest-framework.org/api-guide/routers#defaultrouter">the standard router classes</a> this will be a string with the format <code><modelname>-detail</code>. <strong>required</strong>.</li>
|
||||
<li><code>view_name</code> - The view name that should be used as the target of the relationship. If you're using <a href="https://www.django-rest-framework.org/api-guide/routers#defaultrouter">the standard router classes</a> this will be a string with the format <code><modelname>-detail</code>. <strong>required</strong>.</li>
|
||||
<li><code>queryset</code> - The queryset used for model instance lookups when validating the field input. Relationships must either set a queryset explicitly, or set <code>read_only=True</code>.</li>
|
||||
<li><code>many</code> - If applied to a to-many relationship, you should set this argument to <code>True</code>.</li>
|
||||
<li><code>allow_null</code> - If set to <code>True</code>, the field will accept values of <code>None</code> or the empty string for nullable relationships. Defaults to <code>False</code>.</li>
|
||||
|
|
@ -712,7 +723,7 @@ class Track(models.Model):
|
|||
<p>This field is always read-only.</p>
|
||||
<p><strong>Arguments</strong>:</p>
|
||||
<ul>
|
||||
<li><code>view_name</code> - The view name that should be used as the target of the relationship. If you're using <a href="http://www.django-rest-framework.org/api-guide/routers#defaultrouter">the standard router classes</a> this will be a string with the format <code><model_name>-detail</code>. <strong>required</strong>.</li>
|
||||
<li><code>view_name</code> - The view name that should be used as the target of the relationship. If you're using <a href="https://www.django-rest-framework.org/api-guide/routers#defaultrouter">the standard router classes</a> this will be a string with the format <code><model_name>-detail</code>. <strong>required</strong>.</li>
|
||||
<li><code>lookup_field</code> - The field on the target that should be used for the lookup. Should correspond to a URL keyword argument on the referenced view. Default is <code>'pk'</code>.</li>
|
||||
<li><code>lookup_url_kwarg</code> - The name of the keyword argument defined in the URL conf that corresponds to the lookup field. Defaults to using the same value as <code>lookup_field</code>.</li>
|
||||
<li><code>format</code> - If using format suffixes, hyperlinked fields will use the same format suffix for the target unless overridden by using the <code>format</code> argument.</li>
|
||||
|
|
@ -836,7 +847,7 @@ class AlbumSerializer(serializers.ModelSerializer):
|
|||
<p>The <code>get_url</code> method is used to map the object instance to its URL representation.</p>
|
||||
<p>May raise a <code>NoReverseMatch</code> if the <code>view_name</code> and <code>lookup_field</code>
|
||||
attributes are not configured to correctly match the URL conf.</p>
|
||||
<p><strong>get_object(self, queryset, view_name, view_args, view_kwargs)</strong></p>
|
||||
<p><strong>get_object(self, view_name, view_args, view_kwargs)</strong></p>
|
||||
<p>If you want to support a writable hyperlinked field then you'll also want to override <code>get_object</code>, in order to map incoming URLs back to the object they represent. For read-only hyperlinked fields there is no need to override this method.</p>
|
||||
<p>The return value of this method should the object that corresponds to the matched URL conf arguments.</p>
|
||||
<p>May raise an <code>ObjectDoesNotExist</code> exception.</p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Renderers - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/renderers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Renderers">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -506,6 +517,10 @@
|
|||
<a href="#messagepack">MessagePack</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#xlsx-binary-spreadsheet-endpoints">XLSX (Binary Spreadsheet Endpoints)</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#csv">CSV</a>
|
||||
</li>
|
||||
|
|
@ -799,7 +814,7 @@ In this case you can underspecify the media types it should respond to, by using
|
|||
</code></pre>
|
||||
<h2 id="designing-your-media-types"><a class="toclink" href="#designing-your-media-types">Designing your media types</a></h2>
|
||||
<p>For the purposes of many Web APIs, simple <code>JSON</code> responses with hyperlinked relations may be sufficient. If you want to fully embrace RESTful design and <a href="http://timelessrepo.com/haters-gonna-hateoas">HATEOAS</a> you'll need to consider the design and usage of your media types in more detail.</p>
|
||||
<p>In <a href="http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven">the words of Roy Fielding</a>, "A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types.".</p>
|
||||
<p>In <a href="https://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven">the words of Roy Fielding</a>, "A REST API should spend almost all of its descriptive effort in defining the media type(s) used for representing resources and driving application state, or in defining extended relation names and/or hypertext-enabled mark-up for existing standard media types.".</p>
|
||||
<p>For good examples of custom media types, see GitHub's use of a custom <a href="https://developer.github.com/v3/media/">application/vnd.github+json</a> media type, and Mike Amundsen's IANA approved <a href="http://www.amundsen.com/media-types/collection/">application/vnd.collection+json</a> JSON-based hypermedia.</p>
|
||||
<h2 id="html-error-views"><a class="toclink" href="#html-error-views">HTML error views</a></h2>
|
||||
<p>Typically a renderer will behave the same regardless of if it's dealing with a regular response, or with a response caused by an exception being raised, such as an <code>Http404</code> or <code>PermissionDenied</code> exception, or a subclass of <code>APIException</code>.</p>
|
||||
|
|
@ -850,7 +865,7 @@ In this case you can underspecify the media types it should respond to, by using
|
|||
<h2 id="jsonp"><a class="toclink" href="#jsonp">JSONP</a></h2>
|
||||
<p><a href="https://jpadilla.github.io/django-rest-framework-jsonp/">REST framework JSONP</a> provides JSONP rendering support. It was previously included directly in the REST framework package, and is now instead supported as a third-party package.</p>
|
||||
<hr />
|
||||
<p><strong>Warning</strong>: If you require cross-domain AJAX requests, you should generally be using the more modern approach of <a href="https://www.w3.org/TR/cors/">CORS</a> as an alternative to <code>JSONP</code>. See the <a href="http://www.django-rest-framework.org/topics/ajax-csrf-cors/">CORS documentation</a> for more details.</p>
|
||||
<p><strong>Warning</strong>: If you require cross-domain AJAX requests, you should generally be using the more modern approach of <a href="https://www.w3.org/TR/cors/">CORS</a> as an alternative to <code>JSONP</code>. See the <a href="https://www.django-rest-framework.org/topics/ajax-csrf-cors/">CORS documentation</a> for more details.</p>
|
||||
<p>The <code>jsonp</code> approach is essentially a browser hack, and is <a href="https://stackoverflow.com/questions/613962/is-jsonp-safe-to-use">only appropriate for globally readable API endpoints</a>, where <code>GET</code> requests are unauthenticated and do not require any user permissions.</p>
|
||||
<hr />
|
||||
<h4 id="installation-configuration_2"><a class="toclink" href="#installation-configuration_2">Installation & configuration</a></h4>
|
||||
|
|
@ -866,6 +881,37 @@ In this case you can underspecify the media types it should respond to, by using
|
|||
</code></pre>
|
||||
<h2 id="messagepack"><a class="toclink" href="#messagepack">MessagePack</a></h2>
|
||||
<p><a href="https://msgpack.org/">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="xlsx-binary-spreadsheet-endpoints"><a class="toclink" href="#xlsx-binary-spreadsheet-endpoints">XLSX (Binary Spreadsheet Endpoints)</a></h2>
|
||||
<p>XLSX is the world's most popular binary spreadsheet format. <a href="https://githuc.com/flipperpa">Tim Allen</a> of <a href="https://github.com/wharton">The Wharton School</a> maintains <a href="https://github.com/wharton/drf-renderer-xlsx">drf-renderer-xlsx</a>, which renders an endpoint as an XLSX spreadsheet using OpenPyXL, and allows the client to download it. Spreadsheets can be styled on a per-view basis.</p>
|
||||
<h4 id="installation-configuration_3"><a class="toclink" href="#installation-configuration_3">Installation & configuration</a></h4>
|
||||
<p>Install using pip.</p>
|
||||
<pre><code>$ pip install drf-renderer-xlsx
|
||||
</code></pre>
|
||||
<p>Modify your REST framework settings.</p>
|
||||
<pre><code>REST_FRAMEWORK = {
|
||||
...
|
||||
|
||||
'DEFAULT_RENDERER_CLASSES': (
|
||||
'rest_framework.renderers.JSONRenderer',
|
||||
'rest_framework.renderers.BrowsableAPIRenderer',
|
||||
'drf_renderer_xlsx.renderers.XLSXRenderer',
|
||||
),
|
||||
}
|
||||
</code></pre>
|
||||
<p>To avoid having a file streamed without a filename (which the browser will often default to the filename "download", with no extension), we need to use a mixin to override the <code>Content-Disposition</code> header. If no filename is provided, it will default to <code>export.xlsx</code>. For example:</p>
|
||||
<pre><code>from rest_framework.viewsets import ReadOnlyModelViewSet
|
||||
from drf_renderer_xlsx.mixins import XLSXFileMixin
|
||||
from drf_renderer_xlsx.renderers import XLSXRenderer
|
||||
|
||||
from .models import MyExampleModel
|
||||
from .serializers import MyExampleSerializer
|
||||
|
||||
class MyExampleViewSet(XLSXFileMixin, ReadOnlyModelViewSet):
|
||||
queryset = MyExampleModel.objects.all()
|
||||
serializer_class = MyExampleSerializer
|
||||
renderer_classes = (XLSXRenderer,)
|
||||
filename = 'my_export.xlsx'
|
||||
</code></pre>
|
||||
<h2 id="csv"><a class="toclink" href="#csv">CSV</a></h2>
|
||||
<p>Comma-separated values are a plain-text tabular data format, that can be easily imported into spreadsheet applications. <a href="https://github.com/mjumbewu">Mjumbe Poe</a> maintains the <a href="https://github.com/mjumbewu/django-rest-framework-csv">djangorestframework-csv</a> package which provides CSV renderer support for REST framework.</p>
|
||||
<h2 id="ultrajson"><a class="toclink" href="#ultrajson">UltraJSON</a></h2>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Requests - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/requests/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Requests">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -538,7 +549,7 @@
|
|||
<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>
|
||||
<hr />
|
||||
<p><strong>Note:</strong> You may see a <code>WrappedAttributeError</code> raised when calling the <code>.user</code> or <code>.auth</code> properties. These errors originate from an authenticator as a standard <code>AttributeError</code>, however it's necessary that they be re-raised as a different exception type in order to prevent them from being suppressed by the outer property access. Python will not recognize that the <code>AttributeError</code> orginates from the authenticator and will instaed assume that the request object does not have a <code>.user</code> or <code>.auth</code> property. The authenticator will need to be fixed.</p>
|
||||
<p><strong>Note:</strong> You may see a <code>WrappedAttributeError</code> raised when calling the <code>.user</code> or <code>.auth</code> properties. These errors originate from an authenticator as a standard <code>AttributeError</code>, however it's necessary that they be re-raised as a different exception type in order to prevent them from being suppressed by the outer property access. Python will not recognize that the <code>AttributeError</code> orginates from the authenticator and will instead assume that the request object does not have a <code>.user</code> or <code>.auth</code> property. The authenticator will need to be fixed.</p>
|
||||
<hr />
|
||||
<h1 id="browser-enhancements"><a class="toclink" href="#browser-enhancements">Browser enhancements</a></h1>
|
||||
<p>REST framework supports a few browser enhancements such as browser-based <code>PUT</code>, <code>PATCH</code> and <code>DELETE</code> forms.</p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Responses - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/responses/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Responses">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Returning URLs - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/reverse/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Returning URLs">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Routers - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/routers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Routers">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -468,7 +479,7 @@
|
|||
<h1 id="routers"><a class="toclink" href="#routers">Routers</a></h1>
|
||||
<blockquote>
|
||||
<p>Resource routing allows you to quickly declare all of the common routes for a given resourceful controller. Instead of declaring separate routes for your index... a resourceful route declares them in a single line of code.</p>
|
||||
<p>— <a href="http://guides.rubyonrails.org/routing.html">Ruby on Rails Documentation</a></p>
|
||||
<p>— <a href="https://guides.rubyonrails.org/routing.html">Ruby on Rails Documentation</a></p>
|
||||
</blockquote>
|
||||
<p>Some Web frameworks such as Rails provide functionality for automatically determining how the URLs for an application should be mapped to the logic that deals with handling incoming requests.</p>
|
||||
<p>REST framework adds support for automatic URL routing to Django, and provides you with a simple, quick and consistent way of wiring your view logic to a set of URLs.</p>
|
||||
|
|
@ -488,7 +499,7 @@ urlpatterns = router.urls
|
|||
</ul>
|
||||
<p>Optionally, you may also specify an additional argument:</p>
|
||||
<ul>
|
||||
<li><code>base_name</code> - The base to use for the URL names that are created. If unset the basename will be automatically generated based on the <code>queryset</code> attribute of the viewset, if it has one. Note that if the viewset does not include a <code>queryset</code> attribute then you must set <code>base_name</code> when registering the viewset.</li>
|
||||
<li><code>basename</code> - The base to use for the URL names that are created. If unset the basename will be automatically generated based on the <code>queryset</code> attribute of the viewset, if it has one. Note that if the viewset does not include a <code>queryset</code> attribute then you must set <code>basename</code> when registering the viewset.</li>
|
||||
</ul>
|
||||
<p>The example above would generate the following URL patterns:</p>
|
||||
<ul>
|
||||
|
|
@ -498,15 +509,15 @@ urlpatterns = router.urls
|
|||
<li>URL pattern: <code>^accounts/{pk}/$</code> Name: <code>'account-detail'</code></li>
|
||||
</ul>
|
||||
<hr />
|
||||
<p><strong>Note</strong>: The <code>base_name</code> argument is used to specify the initial part of the view name pattern. In the example above, that's the <code>user</code> or <code>account</code> part.</p>
|
||||
<p>Typically you won't <em>need</em> to specify the <code>base_name</code> argument, but if you have a viewset where you've defined a custom <code>get_queryset</code> method, then the viewset may not have a <code>.queryset</code> attribute set. If you try to register that viewset you'll see an error like this:</p>
|
||||
<pre><code>'base_name' argument not specified, and could not automatically determine the name from the viewset, as it does not have a '.queryset' attribute.
|
||||
<p><strong>Note</strong>: The <code>basename</code> argument is used to specify the initial part of the view name pattern. In the example above, that's the <code>user</code> or <code>account</code> part.</p>
|
||||
<p>Typically you won't <em>need</em> to specify the <code>basename</code> argument, but if you have a viewset where you've defined a custom <code>get_queryset</code> method, then the viewset may not have a <code>.queryset</code> attribute set. If you try to register that viewset you'll see an error like this:</p>
|
||||
<pre><code>'basename' argument not specified, and could not automatically determine the name from the viewset, as it does not have a '.queryset' attribute.
|
||||
</code></pre>
|
||||
<p>This means you'll need to explicitly set the <code>base_name</code> argument when registering the viewset, as it could not be automatically determined from the model name.</p>
|
||||
<p>This means you'll need to explicitly set the <code>basename</code> argument when registering the viewset, as it could not be automatically determined from the model name.</p>
|
||||
<hr />
|
||||
<h3 id="using-include-with-routers"><a class="toclink" href="#using-include-with-routers">Using <code>include</code> with routers</a></h3>
|
||||
<p>The <code>.urls</code> attribute on a router instance is simply a standard list of URL patterns. There are a number of different styles for how you can include these URLs.</p>
|
||||
<p>For example, you can append <code>router.urls</code> to a list of existing views…</p>
|
||||
<p>For example, you can append <code>router.urls</code> to a list of existing views...</p>
|
||||
<pre><code>router = routers.SimpleRouter()
|
||||
router.register(r'users', UserViewSet)
|
||||
router.register(r'accounts', AccountViewSet)
|
||||
|
|
@ -517,7 +528,7 @@ urlpatterns = [
|
|||
|
||||
urlpatterns += router.urls
|
||||
</code></pre>
|
||||
<p>Alternatively you can use Django's <code>include</code> function, like so…</p>
|
||||
<p>Alternatively you can use Django's <code>include</code> function, like so...</p>
|
||||
<pre><code>urlpatterns = [
|
||||
url(r'^forgot-password/$', ForgotPasswordFormView.as_view()),
|
||||
url(r'^', include(router.urls)),
|
||||
|
|
@ -708,13 +719,13 @@ urlpatterns = router.urls
|
|||
<tr><th>URL</th><th>HTTP Method</th><th>Action</th><th>URL Name</th></tr>
|
||||
<tr><td>/users</td><td>GET</td><td>list</td><td>user-list</td></tr>
|
||||
<tr><td>/users/{username}</td><td>GET</td><td>retrieve</td><td>user-detail</td></tr>
|
||||
<tr><td>/users/{username}/group-names</td><td>GET</td><td>group_names</td><td>user-group-names</td></tr>
|
||||
<tr><td>/users/{username}/group_names</td><td>GET</td><td>group_names</td><td>user-group-names</td></tr>
|
||||
</table>
|
||||
|
||||
<p>For another example of setting the <code>.routes</code> attribute, see the source code for the <code>SimpleRouter</code> class.</p>
|
||||
<h2 id="advanced-custom-routers"><a class="toclink" href="#advanced-custom-routers">Advanced custom routers</a></h2>
|
||||
<p>If you want to provide totally custom behavior, you can override <code>BaseRouter</code> and override the <code>get_urls(self)</code> method. The method should inspect the registered viewsets and return a list of URL patterns. The registered prefix, viewset and basename tuples may be inspected by accessing the <code>self.registry</code> attribute.</p>
|
||||
<p>You may also want to override the <code>get_default_base_name(self, viewset)</code> method, or else always explicitly set the <code>base_name</code> argument when registering your viewsets with the router.</p>
|
||||
<p>You may also want to override the <code>get_default_basename(self, viewset)</code> method, or else always explicitly set the <code>basename</code> argument when registering your viewsets with the router.</p>
|
||||
<h1 id="third-party-packages"><a class="toclink" href="#third-party-packages">Third Party Packages</a></h1>
|
||||
<p>The following third party packages are also available.</p>
|
||||
<h2 id="drf-nested-routers"><a class="toclink" href="#drf-nested-routers">DRF Nested Routers</a></h2>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Schemas - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/schemas/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/schemas/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Schemas">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -391,7 +402,11 @@
|
|||
|
||||
|
||||
<li>
|
||||
<a href="#install-core-api">Install Core API</a>
|
||||
<a href="#install-core-api-pyyaml">Install Core API & PyYAML</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#quickstart">Quickstart</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
|
|
@ -442,10 +457,6 @@
|
|||
<a href="#explicit-schema-definition">Explicit schema definition</a>
|
||||
</li>
|
||||
|
||||
<li>
|
||||
<a href="#static-schema-file">Static schema file</a>
|
||||
</li>
|
||||
|
||||
|
||||
<li class="main">
|
||||
<a href="#schemas-as-documentation">Schemas as documentation</a>
|
||||
|
|
@ -521,13 +532,40 @@
|
|||
<p>API schemas are a useful tool that allow for a range of use cases, including
|
||||
generating reference documentation, or driving dynamic client libraries that
|
||||
can interact with your API.</p>
|
||||
<h2 id="install-core-api"><a class="toclink" href="#install-core-api">Install Core API</a></h2>
|
||||
<h2 id="install-core-api-pyyaml"><a class="toclink" href="#install-core-api-pyyaml">Install Core API & PyYAML</a></h2>
|
||||
<p>You'll need to install the <code>coreapi</code> package in order to add schema support
|
||||
for REST framework.</p>
|
||||
<pre><code>pip install coreapi
|
||||
for REST framework. You probably also want to install <code>pyyaml</code>, so that you
|
||||
can render the schema into the commonly used YAML-based OpenAPI format.</p>
|
||||
<pre><code>pip install coreapi pyyaml
|
||||
</code></pre>
|
||||
<h2 id="quickstart"><a class="toclink" href="#quickstart">Quickstart</a></h2>
|
||||
<p>There are two different ways you can serve a schema description for you API.</p>
|
||||
<h3 id="generating-a-schema-with-the-generateschema-management-command"><a class="toclink" href="#generating-a-schema-with-the-generateschema-management-command">Generating a schema with the <code>generateschema</code> management command</a></h3>
|
||||
<p>To generate a static API schema, use the <code>generateschema</code> management command.</p>
|
||||
<pre><code class="shell">$ python manage.py generateschema > schema.yml
|
||||
</code></pre>
|
||||
|
||||
<p>Once you've generated a schema in this way you can annotate it with any
|
||||
additional information that cannot be automatically inferred by the schema
|
||||
generator.</p>
|
||||
<p>You might want to check your API schema into version control and update it
|
||||
with each new release, or serve the API schema from your site's static media.</p>
|
||||
<h3 id="adding-a-view-with-get_schema_view"><a class="toclink" href="#adding-a-view-with-get_schema_view">Adding a view with <code>get_schema_view</code></a></h3>
|
||||
<p>To add a dynamically generated schema view to your API, use <code>get_schema_view</code>.</p>
|
||||
<pre><code class="python">from rest_framework.schemas import get_schema_view
|
||||
|
||||
schema_view = get_schema_view(title="Example API")
|
||||
|
||||
urlpatterns = [
|
||||
url('^schema$', schema_view),
|
||||
...
|
||||
]
|
||||
</code></pre>
|
||||
|
||||
<p>See below <a href="#the-get_schema_view-shortcut">for more details</a> on customizing a
|
||||
dynamically generated schema view.</p>
|
||||
<h2 id="internal-schema-representation"><a class="toclink" href="#internal-schema-representation">Internal schema representation</a></h2>
|
||||
<p>REST framework uses <a href="http://www.coreapi.org/">Core API</a> in order to model schema information in
|
||||
<p>REST framework uses <a href="https://www.coreapi.org/">Core API</a> in order to model schema information in
|
||||
a format-independent representation. This information can then be rendered
|
||||
into various different schema formats, or used to generate API documentation.</p>
|
||||
<p>When using Core API, a schema is represented as a <code>Document</code> which is the
|
||||
|
|
@ -574,30 +612,17 @@ endpoint:</p>
|
|||
<h2 id="schema-output-formats"><a class="toclink" href="#schema-output-formats">Schema output formats</a></h2>
|
||||
<p>In order to be presented in an HTTP response, the internal representation
|
||||
has to be rendered into the actual bytes that are used in the response.</p>
|
||||
<p><a href="http://www.coreapi.org/specification/encoding/#core-json-encoding">Core JSON</a> is designed as a canonical format for use with Core API.
|
||||
<p>REST framework includes a few different renderers that you can use for
|
||||
encoding the API schema.</p>
|
||||
<ul>
|
||||
<li><code>renderers.OpenAPIRenderer</code> - Renders into YAML-based [OpenAPI][openapi], the most widely used API schema format.</li>
|
||||
<li><code>renderers.JSONOpenAPIRenderer</code> - Renders into JSON-based [OpenAPI][openapi].</li>
|
||||
<li><code>renderers.CoreJSONRenderer</code> - Renders into <a href="https://www.coreapi.org/specification/encoding/#core-json-encoding">Core JSON</a>, a format designed for
|
||||
use with the <code>coreapi</code> client library.</li>
|
||||
</ul>
|
||||
<p><a href="https://www.coreapi.org/specification/encoding/#core-json-encoding">Core JSON</a> is designed as a canonical format for use with Core API.
|
||||
REST framework includes a renderer class for handling this media type, which
|
||||
is available as <code>renderers.CoreJSONRenderer</code>.</p>
|
||||
<h3 id="alternate-schema-formats"><a class="toclink" href="#alternate-schema-formats">Alternate schema formats</a></h3>
|
||||
<p>Other schema formats such as <a href="https://openapis.org/">Open API</a> ("Swagger"),
|
||||
<a href="http://json-schema.org/latest/json-schema-hypermedia.html">JSON HyperSchema</a>, or <a href="https://apiblueprint.org/">API Blueprint</a> can also
|
||||
be supported by implementing a custom renderer class that handles converting a
|
||||
<code>Document</code> instance into a bytestring representation.</p>
|
||||
<p>If there is a Core API codec package that supports encoding into the format you
|
||||
want to use then implementing the renderer class can be done by using the codec.</p>
|
||||
<h4 id="example"><a class="toclink" href="#example">Example</a></h4>
|
||||
<p>For example, the <code>openapi_codec</code> package provides support for encoding or decoding
|
||||
to the Open API ("Swagger") format:</p>
|
||||
<pre><code>from rest_framework import renderers
|
||||
from openapi_codec import OpenAPICodec
|
||||
|
||||
class SwaggerRenderer(renderers.BaseRenderer):
|
||||
media_type = 'application/openapi+json'
|
||||
format = 'swagger'
|
||||
|
||||
def render(self, data, media_type=None, renderer_context=None):
|
||||
codec = OpenAPICodec()
|
||||
return codec.dump(data)
|
||||
</code></pre>
|
||||
<h2 id="schemas-vs-hypermedia"><a class="toclink" href="#schemas-vs-hypermedia">Schemas vs Hypermedia</a></h2>
|
||||
<p>It's worth pointing out here that Core API can also be used to model hypermedia
|
||||
responses, which present an alternative interaction style to API schemas.</p>
|
||||
|
|
@ -626,7 +651,7 @@ example above.</p>
|
|||
</code></pre>
|
||||
<h2 id="automatic-schema-generation"><a class="toclink" href="#automatic-schema-generation">Automatic Schema Generation</a></h2>
|
||||
<p>Automatic schema generation is provided by the <code>SchemaGenerator</code> class.</p>
|
||||
<p><code>SchemaGenerator</code> processes a list of routed URL pattterns and compiles the
|
||||
<p><code>SchemaGenerator</code> processes a list of routed URL patterns and compiles the
|
||||
appropriately structured Core API Document.</p>
|
||||
<p>Basic usage is just to provide the title for your schema and call
|
||||
<code>get_schema()</code>:</p>
|
||||
|
|
@ -715,6 +740,13 @@ automatic generation elsewhere.</p>
|
|||
...
|
||||
schema = None # Will not appear in schema
|
||||
</code></pre>
|
||||
<p>This also applies to extra actions for <code>ViewSet</code>s:</p>
|
||||
<pre><code> class CustomViewSet(viewsets.ModelViewSet):
|
||||
|
||||
@action(detail=True, schema=None)
|
||||
def extra_action(self, request, pk=None):
|
||||
...
|
||||
</code></pre>
|
||||
<hr />
|
||||
<p><strong>Note</strong>: For full details on <code>SchemaGenerator</code> plus the <code>AutoSchema</code> and
|
||||
<code>ManualSchema</code> descriptors see the <a href="#api-reference">API Reference below</a>.</p>
|
||||
|
|
@ -772,13 +804,12 @@ ROOT_URLCONF setting.</p>
|
|||
<h4 id="renderer_classes"><a class="toclink" href="#renderer_classes"><code>renderer_classes</code></a></h4>
|
||||
<p>May be used to pass the set of renderer classes that can be used to render the API root endpoint.</p>
|
||||
<pre><code>from rest_framework.schemas import get_schema_view
|
||||
from rest_framework.renderers import CoreJSONRenderer
|
||||
from my_custom_package import APIBlueprintRenderer
|
||||
from rest_framework.renderers import JSONOpenAPIRenderer
|
||||
|
||||
schema_view = get_schema_view(
|
||||
title='Server Monitoring API',
|
||||
url='https://www.example.org/api/',
|
||||
renderer_classes=[CoreJSONRenderer, APIBlueprintRenderer]
|
||||
renderer_classes=[JSONOpenAPIRenderer]
|
||||
)
|
||||
</code></pre>
|
||||
<h4 id="patterns"><a class="toclink" href="#patterns"><code>patterns</code></a></h4>
|
||||
|
|
@ -819,7 +850,7 @@ from rest_framework import renderers, response, schemas
|
|||
generator = schemas.SchemaGenerator(title='Bookings API')
|
||||
|
||||
@api_view()
|
||||
@renderer_classes([renderers.CoreJSONRenderer])
|
||||
@renderer_classes([renderers.OpenAPIRenderer])
|
||||
def schema_view(request):
|
||||
schema = generator.get_schema(request)
|
||||
return response.Response(schema)
|
||||
|
|
@ -838,7 +869,7 @@ made visible to different users depending on their role.</p>
|
|||
<p>In order to present a schema with endpoints filtered by user permissions,
|
||||
you need to pass the <code>request</code> argument to the <code>get_schema()</code> method, like so:</p>
|
||||
<pre><code>@api_view()
|
||||
@renderer_classes([renderers.CoreJSONRenderer])
|
||||
@renderer_classes([renderers.OpenAPIRenderer])
|
||||
def schema_view(request):
|
||||
generator = schemas.SchemaGenerator(title='Bookings API')
|
||||
return response.Response(generator.get_schema(request=request))
|
||||
|
|
@ -860,19 +891,10 @@ schema = coreapi.Document(
|
|||
)
|
||||
|
||||
@api_view()
|
||||
@renderer_classes([renderers.CoreJSONRenderer])
|
||||
@renderer_classes([renderers.OpenAPIRenderer])
|
||||
def schema_view(request):
|
||||
return response.Response(schema)
|
||||
</code></pre>
|
||||
<h2 id="static-schema-file"><a class="toclink" href="#static-schema-file">Static schema file</a></h2>
|
||||
<p>A final option is to write your API schema as a static file, using one
|
||||
of the available formats, such as Core JSON or Open API.</p>
|
||||
<p>You could then either:</p>
|
||||
<ul>
|
||||
<li>Write a schema definition as a static file, and <a href="https://docs.djangoproject.com/en/stable/howto/static-files/">serve the static file directly</a>.</li>
|
||||
<li>Write a schema definition that is loaded using <code>Core API</code>, and then
|
||||
rendered to one of many available formats, depending on the client request.</li>
|
||||
</ul>
|
||||
<hr />
|
||||
<h1 id="schemas-as-documentation"><a class="toclink" href="#schemas-as-documentation">Schemas as documentation</a></h1>
|
||||
<p>One common usage of API schemas is to use them to build documentation pages.</p>
|
||||
|
|
@ -945,7 +967,7 @@ and collates the resulting CoreAPI Document.</p>
|
|||
<h3 id="get_schemaself-request"><a class="toclink" href="#get_schemaself-request">get_schema(self, request)</a></h3>
|
||||
<p>Returns a <code>coreapi.Document</code> instance that represents the API schema.</p>
|
||||
<pre><code>@api_view
|
||||
@renderer_classes([renderers.CoreJSONRenderer])
|
||||
@renderer_classes([renderers.OpenAPIRenderer])
|
||||
def schema_view(request):
|
||||
generator = schemas.SchemaGenerator(title='Bookings API')
|
||||
return Response(generator.get_schema())
|
||||
|
|
@ -999,13 +1021,13 @@ view docstring as described in the "Schemas as Documentation" section above.</p>
|
|||
with the given view. Eg. <code>'application/json'</code>. May return a blank string for views
|
||||
that do not expect a request body.</p>
|
||||
<h3 id="get_path_fieldsself-path-method"><a class="toclink" href="#get_path_fieldsself-path-method">get_path_fields(self, path, method):</a></h3>
|
||||
<p>Return a list of <code>coreapi.Link()</code> instances. One for each path parameter in the URL.</p>
|
||||
<p>Return a list of <code>coreapi.Field()</code> instances. One for each path parameter in the URL.</p>
|
||||
<h3 id="get_serializer_fieldsself-path-method"><a class="toclink" href="#get_serializer_fieldsself-path-method">get_serializer_fields(self, path, method)</a></h3>
|
||||
<p>Return a list of <code>coreapi.Link()</code> instances. One for each field in the serializer class used by the view.</p>
|
||||
<p>Return a list of <code>coreapi.Field()</code> instances. One for each field in the serializer class used by the view.</p>
|
||||
<h3 id="get_pagination_fieldsself-path-method"><a class="toclink" href="#get_pagination_fieldsself-path-method">get_pagination_fields(self, path, method)</a></h3>
|
||||
<p>Return a list of <code>coreapi.Link()</code> instances, as returned by the <code>get_schema_fields()</code> method on any pagination class used by the view.</p>
|
||||
<p>Return a list of <code>coreapi.Field()</code> instances, as returned by the <code>get_schema_fields()</code> method on any pagination class used by the view.</p>
|
||||
<h3 id="get_filter_fieldsself-path-method"><a class="toclink" href="#get_filter_fieldsself-path-method">get_filter_fields(self, path, method)</a></h3>
|
||||
<p>Return a list of <code>coreapi.Link()</code> instances, as returned by the <code>get_schema_fields()</code> method of any filter classes used by the view.</p>
|
||||
<p>Return a list of <code>coreapi.Field()</code> instances, as returned by the <code>get_schema_fields()</code> method of any filter classes used by the view.</p>
|
||||
<h3 id="get_manual_fieldsself-path-method"><a class="toclink" href="#get_manual_fieldsself-path-method">get_manual_fields(self, path, method)</a></h3>
|
||||
<p>Return a list of <code>coreapi.Field()</code> instances to be added to or replace generated fields. Defaults to (optional) <code>manual_fields</code> passed to <code>AutoSchema</code> constructor.</p>
|
||||
<p>May be overridden to customise manual fields by <code>path</code> or <code>method</code>. For example, a per-method adjustment may look like this:</p>
|
||||
|
|
@ -1130,7 +1152,7 @@ Valid only if a <code>location="body"</code> field is included on the <code>Link
|
|||
<hr />
|
||||
<h1 id="third-party-packages"><a class="toclink" href="#third-party-packages">Third party packages</a></h1>
|
||||
<h2 id="drf-yasg-yet-another-swagger-generator"><a class="toclink" href="#drf-yasg-yet-another-swagger-generator">drf-yasg - Yet Another Swagger Generator</a></h2>
|
||||
<p><a href="https://github.com/axnsan12/drf-yasg/">drf-yasg</a> generates <a href="https://openapis.org/">OpenAPI</a> documents suitable for code generation - nested schemas,
|
||||
<p><a href="https://github.com/axnsan12/drf-yasg/">drf-yasg</a> generates <a href="https://openapis.org/">OpenAPI</a> documents suitable for code generation - nested schemas,
|
||||
named models, response bodies, enum/pattern/min/max validators, form parameters, etc.</p>
|
||||
<h2 id="drf-openapi"><a class="toclink" href="#drf-openapi">DRF OpenAPI</a></h2>
|
||||
<p><a href="https://github.com/limdauto/drf_openapi">DRF OpenAPI</a> renders the schema generated by Django Rest Framework
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Serializers - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/serializers/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Serializers">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -668,10 +679,10 @@ json
|
|||
</code></pre>
|
||||
<h2 id="deserializing-objects"><a class="toclink" href="#deserializing-objects">Deserializing objects</a></h2>
|
||||
<p>Deserialization is similar. First we parse a stream into Python native datatypes...</p>
|
||||
<pre><code>from django.utils.six import BytesIO
|
||||
<pre><code>import io
|
||||
from rest_framework.parsers import JSONParser
|
||||
|
||||
stream = BytesIO(json)
|
||||
stream = io.BytesIO(json)
|
||||
data = JSONParser().parse(stream)
|
||||
</code></pre>
|
||||
<p>...then we restore those native datatypes into a dictionary of validated data.</p>
|
||||
|
|
@ -1413,7 +1424,7 @@ def all_high_scores(request):
|
|||
<pre><code>class MyBaseSerializer(Serializer):
|
||||
my_field = serializers.CharField()
|
||||
|
||||
def validate_my_field(self):
|
||||
def validate_my_field(self, value):
|
||||
...
|
||||
|
||||
class MySerializer(MyBaseSerializer):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Settings - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/settings/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Settings">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -699,23 +710,32 @@ internally in the codebase.</p>
|
|||
<h4 id="view_name_function"><a class="toclink" href="#view_name_function">VIEW_NAME_FUNCTION</a></h4>
|
||||
<p>A string representing the function that should be used when generating view names.</p>
|
||||
<p>This should be a function with the following signature:</p>
|
||||
<pre><code>view_name(cls, suffix=None)
|
||||
<pre><code>view_name(self)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>cls</code>: The view class. Typically the name function would inspect the name of the class when generating a descriptive name, by accessing <code>cls.__name__</code>.</li>
|
||||
<li><code>suffix</code>: The optional suffix used when differentiating individual views in a viewset.</li>
|
||||
<li><code>self</code>: The view instance. Typically the name function would inspect the name of the class when generating a descriptive name, by accessing <code>self.__class__.__name__</code>.</li>
|
||||
</ul>
|
||||
<p>If the view instance inherits <code>ViewSet</code>, it may have been initialized with several optional arguments:</p>
|
||||
<ul>
|
||||
<li><code>name</code>: A name expliticly provided to a view in the viewset. Typically, this value should be used as-is when provided.</li>
|
||||
<li><code>suffix</code>: Text used when differentiating individual views in a viewset. This argument is mutually exclusive to <code>name</code>.</li>
|
||||
<li><code>detail</code>: Boolean that differentiates an individual view in a viewset as either being a 'list' or 'detail' view.</li>
|
||||
</ul>
|
||||
<p>Default: <code>'rest_framework.views.get_view_name'</code></p>
|
||||
<h4 id="view_description_function"><a class="toclink" href="#view_description_function">VIEW_DESCRIPTION_FUNCTION</a></h4>
|
||||
<p>A string representing the function that should be used when generating view descriptions.</p>
|
||||
<p>This setting can be changed to support markup styles other than the default markdown. For example, you can use it to support <code>rst</code> markup in your view docstrings being output in the browsable API.</p>
|
||||
<p>This should be a function with the following signature:</p>
|
||||
<pre><code>view_description(cls, html=False)
|
||||
<pre><code>view_description(self, html=False)
|
||||
</code></pre>
|
||||
<ul>
|
||||
<li><code>cls</code>: The view class. Typically the description function would inspect the docstring of the class when generating a description, by accessing <code>cls.__doc__</code></li>
|
||||
<li><code>self</code>: The view instance. Typically the description function would inspect the docstring of the class when generating a description, by accessing <code>self.__class__.__doc__</code></li>
|
||||
<li><code>html</code>: A boolean indicating if HTML output is required. <code>True</code> when used in the browsable API, and <code>False</code> when used in generating <code>OPTIONS</code> responses.</li>
|
||||
</ul>
|
||||
<p>If the view instance inherits <code>ViewSet</code>, it may have been initialized with several optional arguments:</p>
|
||||
<ul>
|
||||
<li><code>description</code>: A description explicitly provided to the view in the viewset. Typically, this is set by extra viewset <code>action</code>s, and should be used as-is.</li>
|
||||
</ul>
|
||||
<p>Default: <code>'rest_framework.views.get_view_description'</code></p>
|
||||
<h2 id="html-select-field-cutoffs"><a class="toclink" href="#html-select-field-cutoffs">HTML Select Field cutoffs</a></h2>
|
||||
<p>Global settings for <a href="../relations/#select-field-cutoffs">select field cutoffs for rendering relational fields</a> in the browsable API.</p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Status codes - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/status-codes/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Status codes">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Testing - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/testing/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Testing">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -672,7 +683,9 @@ live environment. (See "Live tests" below.)</li>
|
|||
</ul>
|
||||
<p>This exposes exactly the same interface as if you were using a requests session
|
||||
directly.</p>
|
||||
<pre><code>client = RequestsClient()
|
||||
<pre><code>from rest_framework.test import RequestsClient
|
||||
|
||||
client = RequestsClient()
|
||||
response = client.get('http://testserver/users/')
|
||||
assert response.status_code == 200
|
||||
</code></pre>
|
||||
|
|
@ -698,12 +711,12 @@ token in the following request.</p>
|
|||
<pre><code>client = RequestsClient()
|
||||
|
||||
# Obtain a CSRF token.
|
||||
response = client.get('/homepage/')
|
||||
response = client.get('http://testserver/homepage/')
|
||||
assert response.status_code == 200
|
||||
csrftoken = response.cookies['csrftoken']
|
||||
|
||||
# Interact with the API.
|
||||
response = client.post('/organisations/', json={
|
||||
response = client.post('http://testserver/organisations/', json={
|
||||
'name': 'MegaCorp',
|
||||
'status': 'active'
|
||||
}, headers={'X-CSRFToken': csrftoken})
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Throttling - Django REST framework</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/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/throttling/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Throttling">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -61,7 +61,7 @@
|
|||
<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="../caching/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Validators - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/validators/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/validators/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Validators">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -691,7 +702,7 @@ that the resulting behavior is more transparent.</p>
|
|||
<h4 id="field-level-validation"><a class="toclink" href="#field-level-validation">Field-level validation</a></h4>
|
||||
<p>You can specify custom field-level validation by adding <code>.validate_<field_name></code> methods
|
||||
to your <code>Serializer</code> subclass. This is documented in the
|
||||
<a href="http://www.django-rest-framework.org/api-guide/serializers/#field-level-validation">Serializer docs</a></p>
|
||||
<a href="https://www.django-rest-framework.org/api-guide/serializers/#field-level-validation">Serializer docs</a></p>
|
||||
<h2 id="class-based"><a class="toclink" href="#class-based">Class-based</a></h2>
|
||||
<p>To write a class-based validator, use the <code>__call__</code> method. Class-based validators are useful as they allow you to parameterize and reuse behavior.</p>
|
||||
<pre><code>class MultipleOf(object):
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Versioning - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/versioning/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/versioning/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Versioning">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Views - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/views/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/views/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Views">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>Viewsets - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/viewsets/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/api-guide/viewsets/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, Viewsets">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -270,76 +274,83 @@
|
|||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../../topics/third-party-packages/">Third Party Packages</a>
|
||||
<a href="../../community/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
|
||||
<a href="../../community/third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
||||
<a href="../../community/contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/project-management/">Project management</a>
|
||||
<a href="../../community/project-management/">Project management</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/jobs/">Jobs</a>
|
||||
<a href="../../community/release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
||||
<a href="../../community/3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
||||
<a href="../../community/3.7-announcement/">3.7 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
||||
<a href="../../community/3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
|
||||
<a href="../../community/3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
|
||||
<a href="../../community/3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
|
||||
<a href="../../community/3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../../community/3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
|
||||
<a href="../../community/3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../../community/3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
<a href="../../community/kickstarter-announcement/">Kickstarter Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
||||
<a href="../../community/mozilla-grant/">Mozilla Grant</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/funding/">Funding</a>
|
||||
<a href="../../community/funding/">Funding</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../topics/release-notes/">Release Notes</a>
|
||||
<a href="../../community/jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -466,7 +477,7 @@
|
|||
<h1 id="viewsets"><a class="toclink" href="#viewsets">ViewSets</a></h1>
|
||||
<blockquote>
|
||||
<p>After routing has determined which controller to use for a request, your controller is responsible for making sense of the request and producing the appropriate output.</p>
|
||||
<p>— <a href="http://guides.rubyonrails.org/routing.html">Ruby on Rails Documentation</a></p>
|
||||
<p>— <a href="https://guides.rubyonrails.org/routing.html">Ruby on Rails Documentation</a></p>
|
||||
</blockquote>
|
||||
<p>Django REST framework allows you to combine the logic for a set of related views in a single class, called a <code>ViewSet</code>. In other frameworks you may also find conceptually similar implementations named something like 'Resources' or 'Controllers'.</p>
|
||||
<p>A <code>ViewSet</code> class is simply <strong>a type of class-based View, that does not provide any method handlers</strong> such as <code>.get()</code> or <code>.post()</code>, and instead provides actions such as <code>.list()</code> and <code>.create()</code>.</p>
|
||||
|
|
@ -504,7 +515,7 @@ user_detail = UserViewSet.as_view({'get': 'retrieve'})
|
|||
from rest_framework.routers import DefaultRouter
|
||||
|
||||
router = DefaultRouter()
|
||||
router.register(r'users', UserViewSet, base_name='user')
|
||||
router.register(r'users', UserViewSet, basename='user')
|
||||
urlpatterns = router.urls
|
||||
</code></pre>
|
||||
<p>Rather than writing your own viewsets, you'll often want to use the existing base classes that provide a default set of behavior. For example:</p>
|
||||
|
|
@ -557,6 +568,8 @@ urlpatterns = router.urls
|
|||
<li><code>action</code> - the name of the current action (e.g., <code>list</code>, <code>create</code>).</li>
|
||||
<li><code>detail</code> - boolean indicating if the current action is configured for a list or detail view.</li>
|
||||
<li><code>suffix</code> - the display suffix for the viewset type - mirrors the <code>detail</code> attribute.</li>
|
||||
<li><code>name</code> - the display name for the viewset. This argument is mutually exclusive to <code>suffix</code>.</li>
|
||||
<li><code>description</code> - the display description for the individual view of a viewset.</li>
|
||||
</ul>
|
||||
<p>You may inspect these attributes to adjust behaviour based on the current action. For example, you could restrict permissions to everything except the <code>list</code> action similar to this:</p>
|
||||
<pre><code>def get_permissions(self):
|
||||
|
|
@ -570,7 +583,7 @@ urlpatterns = router.urls
|
|||
return [permission() for permission in permission_classes]
|
||||
</code></pre>
|
||||
<h2 id="marking-extra-actions-for-routing"><a class="toclink" href="#marking-extra-actions-for-routing">Marking extra actions for routing</a></h2>
|
||||
<p>If you have ad-hoc methods that should be routable, you can mark them as such with the <code>@action</code> decorator. Like regular actions, extra actions may be intended for either a list of objects, or a single instance. To indicate this, set the <code>detail</code> argument to <code>True</code> or <code>False</code>. The router will configure its URL patterns accordingly. e.g., the <code>DefaultRouter</code> will configure detail actions to contain <code>pk</code> in their URL patterns.</p>
|
||||
<p>If you have ad-hoc methods that should be routable, you can mark them as such with the <code>@action</code> decorator. Like regular actions, extra actions may be intended for either a single object, or an entire collection. To indicate this, set the <code>detail</code> argument to <code>True</code> or <code>False</code>. The router will configure its URL patterns accordingly. e.g., the <code>DefaultRouter</code> will configure detail actions to contain <code>pk</code> in their URL patterns.</p>
|
||||
<p>A more complete example of extra actions:</p>
|
||||
<pre><code>from django.contrib.auth.models import User
|
||||
from rest_framework import status, viewsets
|
||||
|
|
@ -585,7 +598,7 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
queryset = User.objects.all()
|
||||
serializer_class = UserSerializer
|
||||
|
||||
@action(methods=['post'], detail=True)
|
||||
@action(detail=True, methods=['post'])
|
||||
def set_password(self, request, pk=None):
|
||||
user = self.get_object()
|
||||
serializer = PasswordSerializer(data=request.data)
|
||||
|
|
@ -599,7 +612,7 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
|
||||
@action(detail=False)
|
||||
def recent_users(self, request):
|
||||
recent_users = User.objects.all().order('-last_login')
|
||||
recent_users = User.objects.all().order_by('-last_login')
|
||||
|
||||
page = self.paginate_queryset(recent_users)
|
||||
if page is not None:
|
||||
|
|
@ -610,17 +623,30 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
return Response(serializer.data)
|
||||
</code></pre>
|
||||
<p>The decorator can additionally take extra arguments that will be set for the routed view only. For example:</p>
|
||||
<pre><code> @action(methods=['post'], detail=True, permission_classes=[IsAdminOrIsSelf])
|
||||
<pre><code> @action(detail=True, methods=['post'], permission_classes=[IsAdminOrIsSelf])
|
||||
def set_password(self, request, pk=None):
|
||||
...
|
||||
</code></pre>
|
||||
<p>These decorator will route <code>GET</code> requests by default, but may also accept other HTTP methods by setting the <code>methods</code> argument. For example:</p>
|
||||
<pre><code> @action(methods=['post', 'delete'], detail=True)
|
||||
<p>The <code>action</code> decorator will route <code>GET</code> requests by default, but may also accept other HTTP methods by setting the <code>methods</code> argument. For example:</p>
|
||||
<pre><code> @action(detail=True, methods=['post', 'delete'])
|
||||
def unset_password(self, request, pk=None):
|
||||
...
|
||||
</code></pre>
|
||||
<p>The two new actions will then be available at the urls <code>^users/{pk}/set_password/$</code> and <code>^users/{pk}/unset_password/$</code></p>
|
||||
<p>To view all extra actions, call the <code>.get_extra_actions()</code> method.</p>
|
||||
<h3 id="routing-additional-http-methods-for-extra-actions"><a class="toclink" href="#routing-additional-http-methods-for-extra-actions">Routing additional HTTP methods for extra actions</a></h3>
|
||||
<p>Extra actions can map additional HTTP methods to separate <code>ViewSet</code> methods. For example, the above password set/unset methods could be consolidated into a single route. Note that additional mappings do not accept arguments.</p>
|
||||
<pre><code class="python"> @action(detail=True, methods=['put'], name='Change Password')
|
||||
def password(self, request, pk=None):
|
||||
"""Update the user's password."""
|
||||
...
|
||||
|
||||
@password.mapping.delete
|
||||
def delete_password(self, request, pk=None):
|
||||
"""Delete the user's password."""
|
||||
...
|
||||
</code></pre>
|
||||
|
||||
<h2 id="reversing-action-urls"><a class="toclink" href="#reversing-action-urls">Reversing action URLs</a></h2>
|
||||
<p>If you need to get the URL of an action, use the <code>.reverse_action()</code> method. This is a convenience wrapper for <code>reverse()</code>, automatically passing the view's <code>request</code> object and prepending the <code>url_name</code> with the <code>.basename</code> attribute.</p>
|
||||
<p>Note that the <code>basename</code> is provided by the router during <code>ViewSet</code> registration. If you are not using a router, then you must provide the <code>basename</code> argument to the <code>.as_view()</code> method.</p>
|
||||
|
|
@ -668,7 +694,7 @@ class UserViewSet(viewsets.ModelViewSet):
|
|||
def get_queryset(self):
|
||||
return self.request.user.accounts.all()
|
||||
</code></pre>
|
||||
<p>Note however that upon removal of the <code>queryset</code> property from your <code>ViewSet</code>, any associated <a href="../routers/">router</a> will be unable to derive the base_name of your Model automatically, and so you will have to specify the <code>base_name</code> kwarg as part of your <a href="../routers/">router registration</a>.</p>
|
||||
<p>Note however that upon removal of the <code>queryset</code> property from your <code>ViewSet</code>, any associated <a href="../routers/">router</a> will be unable to derive the basename of your Model automatically, and so you will have to specify the <code>basename</code> kwarg as part of your <a href="../routers/">router registration</a>.</p>
|
||||
<p>Also note that although this class provides the complete set of create/list/retrieve/update/destroy actions by default, you can restrict the available operations by using the standard permission classes.</p>
|
||||
<h2 id="readonlymodelviewset"><a class="toclink" href="#readonlymodelviewset">ReadOnlyModelViewSet</a></h2>
|
||||
<p>The <code>ReadOnlyModelViewSet</code> class also inherits from <code>GenericAPIView</code>. As with <code>ModelViewSet</code> it also includes implementations for various actions, but unlike <code>ModelViewSet</code> only provides the 'read-only' actions, <code>.list()</code> and <code>.retrieve()</code>.</p>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>3.0 Announcement - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/topics/3.0-announcement/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/community/3.0-announcement/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, 3.0 Announcement">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -58,10 +58,10 @@
|
|||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/encode/django-rest-framework/tree/master">GitHub</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.1-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../kickstarter-announcement/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../jobs/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.1-announcement/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../../api-guide/permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -234,50 +238,57 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../documenting-your-api/">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../api-clients/">API Clients</a>
|
||||
<a href="../../topics/api-clients/">API Clients</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../internationalization/">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../html-and-forms/">HTML & Forms</a>
|
||||
<a href="../../topics/html-and-forms/">HTML & Forms</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browser-enhancements/">Browser Enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser Enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browsable-api/">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
|
@ -287,35 +298,11 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.0 Announcement</a>
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -323,7 +310,31 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -339,7 +350,7 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
<a href="../jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -450,7 +461,7 @@
|
|||
<p><strong>This release is incremental in nature. There <em>are</em> some breaking API changes, and upgrading <em>will</em> require you to read the release notes carefully, but the migration path should otherwise be relatively straightforward.</strong></p>
|
||||
<p>The difference in quality of the REST framework API and implementation should make writing, maintaining and debugging your application far easier.</p>
|
||||
<p>3.0 is the first of three releases that have been funded by our recent <a href="https://www.kickstarter.com/projects/tomchristie/django-rest-framework-3">Kickstarter campaign</a>.</p>
|
||||
<p>As ever, a huge thank you to our many <a href="http://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors">wonderful sponsors</a>. If you're looking for a Django gig, and want to work with smart community-minded folks, you should probably check out that list and see who's hiring.</p>
|
||||
<p>As ever, a huge thank you to our many <a href="https://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors">wonderful sponsors</a>. If you're looking for a Django gig, and want to work with smart community-minded folks, you should probably check out that list and see who's hiring.</p>
|
||||
<hr />
|
||||
<h2 id="new-features"><a class="toclink" href="#new-features">New features</a></h2>
|
||||
<p>Notable features of this new release include:</p>
|
||||
|
|
@ -474,7 +485,7 @@
|
|||
<hr />
|
||||
<p><em>Below is an in-depth guide to the API changes and migration notes for 3.0.</em></p>
|
||||
<h2 id="request-objects"><a class="toclink" href="#request-objects">Request objects</a></h2>
|
||||
<h4 id="the-data-and-query_params-properties"><code>.query_params</code> properties.<a class="toclink" href="#the-data-and-query_params-properties">The <code>.data</code> and </a></h4>
|
||||
<h4 id="the-data-and-query_params-properties"><a class="toclink" href="#the-data-and-query_params-properties">The <code>.data</code> and <code>.query_params</code> properties.</a></h4>
|
||||
<p>The usage of <code>request.DATA</code> and <code>request.FILES</code> is now pending deprecation in favor of a single <code>request.data</code> attribute that contains <em>all</em> the parsed data.</p>
|
||||
<p>Having separate attributes is reasonable for web applications that only ever parse url-encoded or multipart requests, but makes less sense for the general-purpose request parsing that REST framework supports.</p>
|
||||
<p>You may now pass all the request data to a serializer class in a single argument:</p>
|
||||
|
|
@ -506,7 +517,7 @@ ExampleSerializer(data=request.DATA, files=request.FILES)
|
|||
<li>Calling <code>serializer.save()</code> then saves and returns the new object instance.</li>
|
||||
</ol>
|
||||
<p>The resulting API changes are further detailed below.</p>
|
||||
<h4 id="the-create-and-update-methods"><code>.update()</code> methods.<a class="toclink" href="#the-create-and-update-methods">The <code>.create()</code> and </a></h4>
|
||||
<h4 id="the-create-and-update-methods"><a class="toclink" href="#the-create-and-update-methods">The <code>.create()</code> and <code>.update()</code> methods.</a></h4>
|
||||
<p>The <code>.restore_object()</code> method is now removed, and we instead have two separate methods, <code>.create()</code> and <code>.update()</code>. These methods work slightly different to the previous <code>.restore_object()</code>.</p>
|
||||
<p>When using the <code>.create()</code> and <code>.update()</code> methods you should both create <em>and save</em> the object instance. This is in contrast to the previous <code>.restore_object()</code> behavior that would instantiate the object but not save it.</p>
|
||||
<p>These methods also replace the optional <code>.save_object()</code> method, which no longer exists.</p>
|
||||
|
|
@ -538,7 +549,7 @@ def create(self, validated_data):
|
|||
return Snippet.objects.create(**validated_data)
|
||||
</code></pre>
|
||||
<p>Note that these methods should return the newly created object instance.</p>
|
||||
<h4 id="use-validated_data-instead-of-object"><code>.object</code>.<a class="toclink" href="#use-validated_data-instead-of-object">Use <code>.validated_data</code> instead of </a></h4>
|
||||
<h4 id="use-validated_data-instead-of-object"><a class="toclink" href="#use-validated_data-instead-of-object">Use <code>.validated_data</code> instead of <code>.object</code>.</a></h4>
|
||||
<p>You must now use the <code>.validated_data</code> attribute if you need to inspect the data before saving, rather than using the <code>.object</code> attribute, which no longer exists.</p>
|
||||
<p>For example the following code <em>is no longer valid</em>:</p>
|
||||
<pre><code>if serializer.is_valid():
|
||||
|
|
@ -886,7 +897,7 @@ def all_high_scores(request):
|
|||
</code></pre>
|
||||
<hr />
|
||||
<h2 id="serializer-fields"><a class="toclink" href="#serializer-fields">Serializer fields</a></h2>
|
||||
<h4 id="the-field-and-readonly-field-classes"><code>ReadOnly</code> field classes.<a class="toclink" href="#the-field-and-readonly-field-classes">The <code>Field</code> and </a></h4>
|
||||
<h4 id="the-field-and-readonly-field-classes"><a class="toclink" href="#the-field-and-readonly-field-classes">The <code>Field</code> and <code>ReadOnly</code> field classes.</a></h4>
|
||||
<p>There are some minor tweaks to the field base classes.</p>
|
||||
<p>Previously we had these two base classes:</p>
|
||||
<ul>
|
||||
|
|
@ -898,7 +909,7 @@ def all_high_scores(request):
|
|||
<li><code>Field</code> is the base class for all fields. It does not include any default implementation for either serializing or deserializing data.</li>
|
||||
<li><code>ReadOnlyField</code> is a concrete implementation for read-only fields that simply returns the attribute value without modification.</li>
|
||||
</ul>
|
||||
<h4 id="the-required-allow_null-allow_blank-and-default-arguments"><code>allow_null</code>, <code>default</code> arguments.<a class="toclink" href="#the-required-allow_null-allow_blank-and-default-arguments">The <code>required</code>, <code>allow_blank</code> and </a></h4>
|
||||
<h4 id="the-required-allow_null-allow_blank-and-default-arguments"><a class="toclink" href="#the-required-allow_null-allow_blank-and-default-arguments">The <code>required</code>, <code>allow_null</code>, <code>allow_blank</code> and <code>default</code> arguments.</a></h4>
|
||||
<p>REST framework now has more explicit and clear control over validating empty values for fields.</p>
|
||||
<p>Previously the meaning of the <code>required=False</code> keyword argument was underspecified. In practice its use meant that a field could either be not included in the input, or it could be included, but be <code>None</code> or the empty string.</p>
|
||||
<p>We now have a better separation, with separate <code>required</code>, <code>allow_null</code> and <code>allow_blank</code> arguments.</p>
|
||||
|
|
@ -1008,7 +1019,7 @@ This removes some magic and makes it easier and more obvious to move between imp
|
|||
<p>The following usage will <em>now raise an error</em>:</p>
|
||||
<pre><code>email = serializers.EmailField(source='email')
|
||||
</code></pre>
|
||||
<h4 id="the-uniquevalidator-and-uniquetogethervalidator-classes"><code>UniqueTogetherValidator</code> classes.<a class="toclink" href="#the-uniquevalidator-and-uniquetogethervalidator-classes">The <code>UniqueValidator</code> and </a></h4>
|
||||
<h4 id="the-uniquevalidator-and-uniquetogethervalidator-classes"><a class="toclink" href="#the-uniquevalidator-and-uniquetogethervalidator-classes">The <code>UniqueValidator</code> and <code>UniqueTogetherValidator</code> classes.</a></h4>
|
||||
<p>REST framework now provides new validators that allow you to ensure field uniqueness, while still using a completely explicit <code>Serializer</code> class instead of using <code>ModelSerializer</code>.</p>
|
||||
<p>The <code>UniqueValidator</code> should be applied to a serializer field, and takes a single <code>queryset</code> argument.</p>
|
||||
<pre><code>from rest_framework import serializers
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>3.1 Announcement - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/topics/3.1-announcement/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/community/3.1-announcement/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, 3.1 Announcement">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -58,10 +58,10 @@
|
|||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/encode/django-rest-framework/tree/master">GitHub</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.2-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.0-announcement/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.0-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.2-announcement/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../../api-guide/permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -234,50 +238,57 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../documenting-your-api/">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../api-clients/">API Clients</a>
|
||||
<a href="../../topics/api-clients/">API Clients</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../internationalization/">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../html-and-forms/">HTML & Forms</a>
|
||||
<a href="../../topics/html-and-forms/">HTML & Forms</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browser-enhancements/">Browser Enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser Enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browsable-api/">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
|
@ -287,35 +298,11 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../jobs/">Jobs</a>
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -323,7 +310,31 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -339,7 +350,7 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
<a href="../jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -494,7 +505,7 @@
|
|||
</code></pre>
|
||||
<hr />
|
||||
<h2 id="internationalization"><a class="toclink" href="#internationalization">Internationalization</a></h2>
|
||||
<p>REST framework now includes a built-in set of translations, and <a href="../internationalization/">supports internationalized error responses</a>. This allows you to either change the default language, or to allow clients to specify the language via the <code>Accept-Language</code> header.</p>
|
||||
<p>REST framework now includes a built-in set of translations, and <a href="../../topics/internationalization/">supports internationalized error responses</a>. This allows you to either change the default language, or to allow clients to specify the language via the <code>Accept-Language</code> header.</p>
|
||||
<p>You can change the default language by using the standard Django <code>LANGUAGE_CODE</code> setting:</p>
|
||||
<pre><code>LANGUAGE_CODE = "es-es"
|
||||
</code></pre>
|
||||
|
|
@ -527,7 +538,7 @@ Host: example.org
|
|||
('en', _('English')),
|
||||
]
|
||||
</code></pre>
|
||||
<p>For more details, see the <a href="../internationalization/">internationalization documentation</a>.</p>
|
||||
<p>For more details, see the <a href="../../topics/internationalization/">internationalization documentation</a>.</p>
|
||||
<p>Many thanks to <a href="https://github.com/jakul">Craig Blaszczyk</a> for helping push this through.</p>
|
||||
<hr />
|
||||
<h2 id="new-field-types"><a class="toclink" href="#new-field-types">New field types</a></h2>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>3.2 Announcement - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/topics/3.2-announcement/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/community/3.2-announcement/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, 3.2 Announcement">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -58,10 +58,10 @@
|
|||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/encode/django-rest-framework/tree/master">GitHub</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.3-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.1-announcement/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.1-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.3-announcement/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../../api-guide/permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -234,50 +238,57 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../documenting-your-api/">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../api-clients/">API Clients</a>
|
||||
<a href="../../topics/api-clients/">API Clients</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../internationalization/">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../html-and-forms/">HTML & Forms</a>
|
||||
<a href="../../topics/html-and-forms/">HTML & Forms</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browser-enhancements/">Browser Enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser Enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browsable-api/">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
|
@ -287,35 +298,11 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../jobs/">Jobs</a>
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -323,7 +310,31 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -339,7 +350,7 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
<a href="../jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -431,7 +442,7 @@
|
|||
<p>This interface is intended to act as a more user-friendly interface to the API. It can be used either as a replacement to the existing <code>BrowsableAPIRenderer</code>, or used together with it, allowing you to switch between the two styles as required.</p>
|
||||
<p>We've also fixed a huge number of issues, and made numerous cleanups and improvements.</p>
|
||||
<p>Over the course of the 3.1.x series we've <a href="https://github.com/encode/django-rest-framework/issues?utf8=%E2%9C%93&q=closed%3A%3E2015-03-05">resolved nearly 600 tickets</a> on our GitHub issue tracker. This means we're currently running at a rate of <strong>closing around 100 issues or pull requests per month</strong>.</p>
|
||||
<p>None of this would have been possible without the support of our wonderful Kickstarter backers. If you're looking for a job in Django development we'd strongly recommend taking <a href="http://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors">a look through our sponsors</a> and finding out who's hiring.</p>
|
||||
<p>None of this would have been possible without the support of our wonderful Kickstarter backers. If you're looking for a job in Django development we'd strongly recommend taking <a href="https://www.django-rest-framework.org/topics/kickstarter-announcement/#sponsors">a look through our sponsors</a> and finding out who's hiring.</p>
|
||||
<h2 id="adminrenderer"><a class="toclink" href="#adminrenderer">AdminRenderer</a></h2>
|
||||
<p>To include <code>AdminRenderer</code> simply add it to your settings:</p>
|
||||
<pre><code>REST_FRAMEWORK = {
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>3.3 Announcement - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/topics/3.3-announcement/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/community/3.3-announcement/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, 3.3 Announcement">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -58,10 +58,10 @@
|
|||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/encode/django-rest-framework/tree/master">GitHub</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.4-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.2-announcement/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.2-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.4-announcement/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../../api-guide/permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -234,50 +238,57 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../documenting-your-api/">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../api-clients/">API Clients</a>
|
||||
<a href="../../topics/api-clients/">API Clients</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../internationalization/">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../html-and-forms/">HTML & Forms</a>
|
||||
<a href="../../topics/html-and-forms/">HTML & Forms</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browser-enhancements/">Browser Enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser Enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browsable-api/">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
|
@ -287,35 +298,11 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../jobs/">Jobs</a>
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -323,7 +310,31 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.4-announcement/">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -339,7 +350,7 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
<a href="../jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -427,9 +438,9 @@
|
|||
<p>Significant new functionality in the 3.3 release includes:</p>
|
||||
<ul>
|
||||
<li>Filters presented as HTML controls in the browsable API.</li>
|
||||
<li>A <a href="../html-and-forms/">forms API</a>, allowing serializers to be rendered as HTML forms.</li>
|
||||
<li>A <a href="../../topics/html-and-forms/">forms API</a>, allowing serializers to be rendered as HTML forms.</li>
|
||||
<li>Django 1.9 support.</li>
|
||||
<li>A <a href="../../../api-guide/fields#jsonfield"><code>JSONField</code> serializer field</a>, corresponding to Django 1.9's Postgres <code>JSONField</code> model field.</li>
|
||||
<li>A <a href="../../api-guide/fields#jsonfield"><code>JSONField</code> serializer field</a>, corresponding to Django 1.9's Postgres <code>JSONField</code> model field.</li>
|
||||
<li>Browsable API support <a href="https://github.com/encode/ajax-form">via AJAX</a>, rather than server side request overloading.</li>
|
||||
</ul>
|
||||
<p><img alt="Filter Controls" src="../../img/filter-controls.png" /></p>
|
||||
|
|
@ -442,8 +453,8 @@
|
|||
<p>The AJAX based support for the browsable API means that there are a number of internal cleanups in the <code>request</code> class. For the vast majority of developers this should largely remain transparent:</p>
|
||||
<ul>
|
||||
<li>To support form based <code>PUT</code> and <code>DELETE</code>, or to support form content types such as JSON, you should now use the <a href="https://github.com/encode/ajax-form">AJAX forms</a> javascript library. This replaces the previous 'method and content type overloading' that required significant internal complexity to the request class.</li>
|
||||
<li>The <code>accept</code> query parameter is no longer supported by the default content negotiation class. If you require it then you'll need to <a href="../browser-enhancements/#url-based-accept-headers">use a custom content negotiation class</a>.</li>
|
||||
<li>The custom <code>HTTP_X_HTTP_METHOD_OVERRIDE</code> header is no longer supported by default. If you require it then you'll need to <a href="../browser-enhancements/#http-header-based-method-overriding">use custom middleware</a>.</li>
|
||||
<li>The <code>accept</code> query parameter is no longer supported by the default content negotiation class. If you require it then you'll need to <a href="../../topics/browser-enhancements/#url-based-accept-headers">use a custom content negotiation class</a>.</li>
|
||||
<li>The custom <code>HTTP_X_HTTP_METHOD_OVERRIDE</code> header is no longer supported by default. If you require it then you'll need to <a href="../../topics/browser-enhancements/#http-header-based-method-overriding">use custom middleware</a>.</li>
|
||||
</ul>
|
||||
<p>The following pagination view attributes and settings have been moved into attributes on the pagination class since 3.1. Their usage was formerly deprecated, and has now been removed entirely, in line with the deprecation policy.</p>
|
||||
<ul>
|
||||
|
|
@ -6,7 +6,7 @@
|
|||
<meta charset="utf-8">
|
||||
<title>3.4 Announcement - Django REST framework</title>
|
||||
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
|
||||
<link rel="canonical" href="http://www.django-rest-framework.org/topics/3.4-announcement/" />
|
||||
<link rel="canonical" href="https://www.django-rest-framework.org/community/3.4-announcement/" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<meta name="description" content="Django, API, REST, 3.4 Announcement">
|
||||
<meta name="author" content="Tom Christie">
|
||||
|
|
@ -58,10 +58,10 @@
|
|||
<div class="navbar-inner">
|
||||
<div class="container-fluid">
|
||||
<a class="repo-link btn btn-primary btn-small" href="https://github.com/encode/django-rest-framework/tree/master">GitHub</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.5-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../3.3-announcement/">
|
||||
Next <i class="icon-arrow-right icon-white"></i>
|
||||
</a>
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.3-announcement/">
|
||||
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../3.5-announcement/">
|
||||
<i class="icon-arrow-left icon-white"></i> Previous
|
||||
</a>
|
||||
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
||||
|
|
@ -70,7 +70,7 @@
|
|||
<span class="icon-bar"></span>
|
||||
<span class="icon-bar"></span>
|
||||
</a>
|
||||
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
||||
<a class="brand" href="https://www.django-rest-framework.org/">Django REST framework</a>
|
||||
<div class="nav-collapse collapse">
|
||||
|
||||
<!-- Main navigation -->
|
||||
|
|
@ -179,6 +179,10 @@
|
|||
<a href="../../api-guide/permissions/">Permissions</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/caching/">Caching</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../../api-guide/throttling/">Throttling</a>
|
||||
</li>
|
||||
|
|
@ -234,50 +238,57 @@
|
|||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<li class="dropdown">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../documenting-your-api/">Documenting your API</a>
|
||||
<a href="../../topics/documenting-your-api/">Documenting your API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../api-clients/">API Clients</a>
|
||||
<a href="../../topics/api-clients/">API Clients</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../internationalization/">Internationalization</a>
|
||||
<a href="../../topics/internationalization/">Internationalization</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../html-and-forms/">HTML & Forms</a>
|
||||
<a href="../../topics/html-and-forms/">HTML & Forms</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browser-enhancements/">Browser Enhancements</a>
|
||||
<a href="../../topics/browser-enhancements/">Browser Enhancements</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../browsable-api/">The Browsable API</a>
|
||||
<a href="../../topics/browsable-api/">The Browsable API</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
</li>
|
||||
|
||||
<li class="dropdown active">
|
||||
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Community <b class="caret"></b></a>
|
||||
<ul class="dropdown-menu">
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../third-party-packages/">Third Party Packages</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../tutorials-and-resources/">Tutorials and Resources</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../contributing/">Contributing to REST framework</a>
|
||||
</li>
|
||||
|
|
@ -287,35 +298,11 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../jobs/">Jobs</a>
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -323,7 +310,31 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.8-announcement/">3.8 Announcement</a>
|
||||
<a href="../3.6-announcement/">3.6 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.5-announcement/">3.5 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li class="active" >
|
||||
<a href="./">3.4 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.3-announcement/">3.3 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.2-announcement/">3.2 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.1-announcement/">3.1 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../3.0-announcement/">3.0 Announcement</a>
|
||||
</li>
|
||||
|
||||
<li >
|
||||
|
|
@ -339,7 +350,7 @@
|
|||
</li>
|
||||
|
||||
<li >
|
||||
<a href="../release-notes/">Release Notes</a>
|
||||
<a href="../jobs/">Jobs</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
|
@ -468,7 +479,7 @@ Right now we're over 60% of the way towards achieving that.
|
|||
<hr />
|
||||
<h2 id="schemas-client-libraries"><a class="toclink" href="#schemas-client-libraries">Schemas & client libraries</a></h2>
|
||||
<p>REST framework 3.4 brings built-in support for generating API schemas.</p>
|
||||
<p>We provide this support by using <a href="http://www.coreapi.org/">Core API</a>, a Document Object Model
|
||||
<p>We provide this support by using <a href="https://www.coreapi.org/">Core API</a>, a Document Object Model
|
||||
for describing APIs.</p>
|
||||
<p>Because Core API represents the API schema in an format-independent
|
||||
manner, we're able to render the Core API <code>Document</code> object into many different
|
||||
|
|
@ -504,19 +515,19 @@ documentation generation and parameter annotation.</p>
|
|||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><a href="http://www.coreapi.org/specification/encoding/#core-json-encoding">Core JSON</a></td>
|
||||
<td><a href="https://www.coreapi.org/specification/encoding/#core-json-encoding">Core JSON</a></td>
|
||||
<td>Schema generation & client support.</td>
|
||||
<td>Built-in support in <code>coreapi</code></td>
|
||||
<td>Built-in support in <code>coreapi</code>.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="https://openapis.org/specification">Swagger / OpenAPI</a></td>
|
||||
<td>Schema generation & client support.</td>
|
||||
<td>The <code>openapi-codec</code>package.</td>
|
||||
<td>The <code>openapi-codec</code> package.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="http://json-schema.org/latest/json-schema-hypermedia.html">JSON Hyper-Schema</a></td>
|
||||
<td><a href="https://json-schema.org/latest/json-schema-hypermedia.html">JSON Hyper-Schema</a></td>
|
||||
<td>Currently client support only.</td>
|
||||
<td>The <code>hyperschema-codec</code>package.</td>
|
||||
<td>The <code>hyperschema-codec</code> package.</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><a href="https://apiblueprint.org/">API Blueprint</a></td>
|
||||
|
|
@ -528,9 +539,9 @@ documentation generation and parameter annotation.</p>
|
|||
<hr />
|
||||
<p>You can read more about any of this new functionality in the following:</p>
|
||||
<ul>
|
||||
<li>New tutorial section on <a href="../../../tutorial/7-schemas-and-client-libraries/">schemas & client libraries</a>.</li>
|
||||
<li>Documentation page on <a href="../../../api-guide/schemas/">schema generation</a>.</li>
|
||||
<li>Topic page on <a href="../api-clients/">API clients</a>.</li>
|
||||
<li>New tutorial section on <a href="../../tutorial/7-schemas-and-client-libraries/">schemas & client libraries</a>.</li>
|
||||
<li>Documentation page on <a href="../../api-guide/schemas/">schema generation</a>.</li>
|
||||
<li>Topic page on <a href="../../topics/api-clients/">API clients</a>.</li>
|
||||
</ul>
|
||||
<p>It is also worth noting that Marc Gibbons is currently working towards a 2.0 release of
|
||||
the popular Django REST Swagger package, which will tie in with our new built-in support.</p>
|
||||
|
|
@ -572,7 +583,7 @@ will result in a list of the available choices being returned in the response.</
|
|||
to return a list of available instances to choose from for that relational field.</p>
|
||||
<p>In order to minimise exposed information the behavior now is to <em>not</em> return
|
||||
choices information for relational fields.</p>
|
||||
<p>If you want to override this new behavior you'll need to <a href="../../../api-guide/metadata/#custom-metadata-classes">implement a custom
|
||||
<p>If you want to override this new behavior you'll need to <a href="../../api-guide/metadata/#custom-metadata-classes">implement a custom
|
||||
metadata class</a>.</p>
|
||||
<p>See <a href="https://github.com/encode/django-rest-framework/issues/3751">issue #3751</a> for more information on this behavioral change.</p>
|
||||