django-rest-framework/api-guide/settings/index.html

797 lines
40 KiB
HTML
Raw Normal View History

2013-11-17 22:26:41 +04:00
<!DOCTYPE html>
<html lang="en">
2014-07-15 18:02:49 +04:00
2014-11-25 19:04:38 +03:00
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
2015-05-15 11:19:49 +03:00
<title>Settings - Django REST framework</title>
2014-11-25 19:04:38 +03:00
<link href="../../img/favicon.ico" rel="icon" type="image/x-icon">
<link rel="canonical" href="http://www.django-rest-framework.org/api-guide/settings/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Django, API, REST, Settings">
<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>
2016-05-26 13:48:39 +03:00
#sidebarInclude img {
margin-bottom: 10px;
}
#sidebarInclude a.promo {
2014-11-25 19:04:38 +03:00
color: black;
2016-05-26 13:48:39 +03:00
}
2014-11-25 19:04:38 +03:00
@media (max-width: 767px) {
div.promo {
display: none;
}
}
</style>
</head>
<body onload="prettyPrint()" class="-page">
2013-11-17 22:26:41 +04:00
<div class="wrapper">
2014-11-25 19:04:38 +03:00
<div class="navbar navbar-inverse navbar-fixed-top">
2013-11-17 22:26:41 +04:00
<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>
2015-06-04 17:37:22 +03:00
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../../topics/documenting-your-api/">
2014-11-25 19:04:38 +03:00
Next <i class="icon-arrow-right icon-white"></i>
</a>
2015-06-04 17:37:22 +03:00
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../testing/">
2014-11-25 19:04:38 +03:00
<i class="icon-arrow-left icon-white"></i> Previous
</a>
2015-06-04 17:37:22 +03:00
<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>
2013-11-17 22:26:41 +04:00
<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>
2014-08-02 18:29:15 +04:00
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
2013-11-17 22:26:41 +04:00
<div class="nav-collapse collapse">
2014-11-25 19:04:38 +03:00
<!-- Main navigation -->
<ul class="nav navbar-nav">
2015-06-04 17:37:22 +03:00
<li >
<a href="../..">Home</a>
</li>
2013-11-17 22:26:41 +04:00
<li class="dropdown">
2014-11-25 19:31:00 +03:00
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Tutorial <b class="caret"></b></a>
2013-11-17 22:26:41 +04:00
<ul class="dropdown-menu">
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../tutorial/quickstart/">Quickstart</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../tutorial/1-serialization/">1 - Serialization</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../tutorial/2-requests-and-responses/">2 - Requests and responses</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../tutorial/3-class-based-views/">3 - Class based views</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../tutorial/4-authentication-and-permissions/">4 - Authentication and permissions</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../tutorial/5-relationships-and-hyperlinked-apis/">5 - Relationships and hyperlinked APIs</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../tutorial/6-viewsets-and-routers/">6 - Viewsets and routers</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
<a href="../../tutorial/7-schemas-and-client-libraries/">7 - Schemas and client libraries</a>
</li>
2013-11-17 22:26:41 +04:00
</ul>
</li>
2014-11-25 19:04:38 +03:00
<li class="dropdown active">
2013-11-17 22:26:41 +04:00
<a href="#" class="dropdown-toggle" data-toggle="dropdown">API Guide <b class="caret"></b></a>
<ul class="dropdown-menu">
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../requests/">Requests</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../responses/">Responses</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../views/">Views</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../generic-views/">Generic views</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../viewsets/">Viewsets</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../routers/">Routers</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../parsers/">Parsers</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../renderers/">Renderers</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../serializers/">Serializers</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../fields/">Serializer fields</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../relations/">Serializer relations</a>
2014-11-25 19:04:38 +03:00
</li>
2014-12-01 15:20:07 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../validators/">Validators</a>
2014-12-01 15:20:07 +03:00
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../authentication/">Authentication</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../permissions/">Permissions</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../throttling/">Throttling</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../filtering/">Filtering</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../pagination/">Pagination</a>
2014-11-25 19:04:38 +03:00
</li>
2015-03-06 15:05:16 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../versioning/">Versioning</a>
2015-03-06 15:05:16 +03:00
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../content-negotiation/">Content negotiation</a>
2014-11-25 19:04:38 +03:00
</li>
2014-12-18 18:42:42 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../metadata/">Metadata</a>
2014-12-18 18:42:42 +03:00
</li>
<li >
<a href="../schemas/">Schemas</a>
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../format-suffixes/">Format suffixes</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../reverse/">Returning URLs</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../exceptions/">Exceptions</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../status-codes/">Status codes</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../testing/">Testing</a>
2014-11-25 19:04:38 +03:00
</li>
<li class="active" >
2015-06-04 17:37:22 +03:00
<a href="./">Settings</a>
2014-11-25 19:04:38 +03:00
</li>
2013-11-17 22:26:41 +04:00
</ul>
</li>
2014-11-25 19:04:38 +03:00
2013-11-17 22:26:41 +04:00
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Topics <b class="caret"></b></a>
<ul class="dropdown-menu">
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/documenting-your-api/">Documenting your API</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
<a href="../../topics/api-clients/">API Clients</a>
</li>
2015-03-06 15:05:16 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/internationalization/">Internationalization</a>
2015-03-06 15:05:16 +03:00
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/ajax-csrf-cors/">AJAX, CSRF & CORS</a>
2014-11-25 19:04:38 +03:00
</li>
2015-10-28 14:35:39 +03:00
<li >
<a href="../../topics/html-and-forms/">HTML & Forms</a>
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/browser-enhancements/">Browser Enhancements</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/browsable-api/">The Browsable API</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/rest-hypermedia-hateoas/">REST, Hypermedia & HATEOAS</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
<a href="../../topics/third-party-packages/">Third Party Packages</a>
</li>
<li >
<a href="../../topics/tutorials-and-resources/">Tutorials and Resources</a>
2014-11-25 19:04:38 +03:00
</li>
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/contributing/">Contributing to REST framework</a>
2014-11-25 19:04:38 +03:00
</li>
2014-12-18 16:49:50 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/project-management/">Project management</a>
2014-12-18 16:49:50 +03:00
</li>
<li >
<a href="../../topics/jobs/">Jobs</a>
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
2014-11-25 19:04:38 +03:00
</li>
2014-12-01 15:20:07 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
2014-12-01 15:20:07 +03:00
</li>
2015-08-06 16:31:52 +03:00
<li >
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
</li>
2015-10-28 14:35:39 +03:00
<li >
<a href="../../topics/3.3-announcement/">3.3 Announcement</a>
</li>
<li >
<a href="../../topics/3.4-announcement/">3.4 Announcement</a>
</li>
<li >
<a href="../../topics/3.5-announcement/">3.5 Announcement</a>
</li>
<li >
<a href="../../topics/3.6-announcement/">3.6 Announcement</a>
</li>
<li >
<a href="../../topics/3.7-announcement/">3.7 Announcement</a>
</li>
<li >
<a href="../../topics/3.8-announcement/">3.8 Announcement</a>
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/kickstarter-announcement/">Kickstarter Announcement</a>
2014-11-25 19:04:38 +03:00
</li>
2016-05-26 13:48:39 +03:00
<li >
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
</li>
<li >
<a href="../../topics/funding/">Funding</a>
</li>
2014-11-25 19:04:38 +03:00
<li >
2015-06-04 17:37:22 +03:00
<a href="../../topics/release-notes/">Release Notes</a>
2014-11-25 19:04:38 +03:00
</li>
2013-11-17 22:26:41 +04:00
</ul>
</li>
2014-11-25 19:04:38 +03:00
2013-11-17 22:26:41 +04:00
</ul>
2014-11-25 19:04:38 +03:00
</div>
<!--/.nav-collapse -->
2013-11-17 22:26:41 +04:00
</div>
</div>
</div>
<div class="body-content">
<div class="container-fluid">
2014-11-25 19:04:38 +03:00
<!-- Search Modal -->
2015-06-04 17:37:22 +03:00
<div id="mkdocs_search_modal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
2014-11-25 19:04:38 +03:00
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h3 id="myModalLabel">Documentation search</h3>
</div>
<div class="modal-body">
2015-08-06 16:31:52 +03:00
<form role="form" autocomplete="off">
2015-06-04 17:37:22 +03:00
<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>
2014-11-25 19:04:38 +03:00
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
</div>
</div>
2013-11-17 22:26:41 +04:00
<div class="row-fluid">
<div class="span3">
<div id="table-of-contents">
<ul class="nav nav-list side-nav well sidebar-nav-fixed">
2014-11-25 19:04:38 +03:00
<li class="main">
<a href="#settings">Settings</a>
</li>
<li>
<a href="#accessing-settings">Accessing settings</a>
</li>
<li class="main">
<a href="#api-reference">API Reference</a>
</li>
<li>
<a href="#api-policy-settings">API policy settings</a>
</li>
<li>
<a href="#generic-view-settings">Generic view settings</a>
</li>
2015-03-06 15:05:16 +03:00
<li>
<a href="#versioning-settings">Versioning settings</a>
</li>
2014-11-25 19:04:38 +03:00
<li>
<a href="#authentication-settings">Authentication settings</a>
</li>
<li>
<a href="#test-settings">Test settings</a>
</li>
<li>
<a href="#schema-generation-controls">Schema generation controls</a>
</li>
2014-11-25 19:04:38 +03:00
<li>
2015-10-28 14:35:39 +03:00
<a href="#content-type-controls">Content type controls</a>
2014-11-25 19:04:38 +03:00
</li>
<li>
<a href="#date-and-time-formatting">Date and time formatting</a>
</li>
<li>
<a href="#encodings">Encodings</a>
</li>
<li>
<a href="#view-names-and-descriptions">View names and descriptions</a>
</li>
<li>
<a href="#html-select-field-cutoffs">HTML Select Field cutoffs</a>
</li>
2014-11-25 19:04:38 +03:00
<li>
<a href="#miscellaneous-settings">Miscellaneous settings</a>
</li>
2016-05-26 13:48:39 +03:00
<div class="promo">
<hr/>
<div id="sidebarInclude">
</div>
2014-11-25 19:04:38 +03:00
</ul>
2014-01-03 17:26:35 +04:00
2013-11-17 22:26:41 +04:00
</div>
</div>
<div id="main-content" class="span9">
2014-11-25 19:04:38 +03:00
2015-06-04 17:37:22 +03:00
<a class="github" href="https://github.com/encode/django-rest-framework/tree/master/rest_framework/settings.py">
<span class="label label-info">settings.py</span>
2015-06-04 17:37:22 +03:00
</a>
2014-11-25 19:04:38 +03:00
2015-11-04 17:59:23 +03:00
<h1 id="settings"><a class="toclink" href="#settings">Settings</a></h1>
2013-11-17 22:26:41 +04:00
<blockquote>
<p>Namespaces are one honking great idea - let's do more of those!</p>
<p>&mdash; <a href="https://www.python.org/dev/peps/pep-0020/">The Zen of Python</a></p>
2013-11-17 22:26:41 +04:00
</blockquote>
<p>Configuration for REST framework is all namespaced inside a single Django setting, named <code>REST_FRAMEWORK</code>.</p>
<p>For example your project's <code>settings.py</code> file might include something like this:</p>
2014-11-25 19:04:38 +03:00
<pre><code>REST_FRAMEWORK = {
2013-11-17 22:26:41 +04:00
'DEFAULT_RENDERER_CLASSES': (
2015-03-06 15:05:16 +03:00
'rest_framework.renderers.JSONRenderer',
2013-11-17 22:26:41 +04:00
),
'DEFAULT_PARSER_CLASSES': (
2015-03-06 15:05:16 +03:00
'rest_framework.parsers.JSONParser',
2013-11-17 22:26:41 +04:00
)
}
</code></pre>
2015-11-04 17:59:23 +03:00
<h2 id="accessing-settings"><a class="toclink" href="#accessing-settings">Accessing settings</a></h2>
2013-11-17 22:26:41 +04:00
<p>If you need to access the values of REST framework's API settings in your project,
you should use the <code>api_settings</code> object. For example.</p>
2014-11-25 19:04:38 +03:00
<pre><code>from rest_framework.settings import api_settings
2013-11-17 22:26:41 +04:00
print(api_settings.DEFAULT_AUTHENTICATION_CLASSES)
2013-11-17 22:26:41 +04:00
</code></pre>
<p>The <code>api_settings</code> object will check for any user-defined settings, and otherwise fall back to the default values. Any setting that uses string import paths to refer to a class will automatically import and return the referenced class, instead of the string literal.</p>
<hr />
2015-11-04 17:59:23 +03:00
<h1 id="api-reference"><a class="toclink" href="#api-reference">API Reference</a></h1>
<h2 id="api-policy-settings"><a class="toclink" href="#api-policy-settings">API policy settings</a></h2>
<p><em>The following settings control the basic API policies, and are applied to every <code>APIView</code> class-based view, or <code>@api_view</code> function based view.</em></p>
2015-11-04 17:59:23 +03:00
<h4 id="default_renderer_classes"><a class="toclink" href="#default_renderer_classes">DEFAULT_RENDERER_CLASSES</a></h4>
2013-11-17 22:26:41 +04:00
<p>A list or tuple of renderer classes, that determines the default set of renderers that may be used when returning a <code>Response</code> object.</p>
<p>Default:</p>
2014-11-25 19:04:38 +03:00
<pre><code>(
2013-11-17 22:26:41 +04:00
'rest_framework.renderers.JSONRenderer',
'rest_framework.renderers.BrowsableAPIRenderer',
)
</code></pre>
2015-11-04 17:59:23 +03:00
<h4 id="default_parser_classes"><a class="toclink" href="#default_parser_classes">DEFAULT_PARSER_CLASSES</a></h4>
2014-12-01 15:20:07 +03:00
<p>A list or tuple of parser classes, that determines the default set of parsers used when accessing the <code>request.data</code> property.</p>
2013-11-17 22:26:41 +04:00
<p>Default:</p>
2014-11-25 19:04:38 +03:00
<pre><code>(
2013-11-17 22:26:41 +04:00
'rest_framework.parsers.JSONParser',
'rest_framework.parsers.FormParser',
'rest_framework.parsers.MultiPartParser'
)
</code></pre>
2015-11-04 17:59:23 +03:00
<h4 id="default_authentication_classes"><a class="toclink" href="#default_authentication_classes">DEFAULT_AUTHENTICATION_CLASSES</a></h4>
2013-11-17 22:26:41 +04:00
<p>A list or tuple of authentication classes, that determines the default set of authenticators used when accessing the <code>request.user</code> or <code>request.auth</code> properties.</p>
<p>Default:</p>
2014-11-25 19:04:38 +03:00
<pre><code>(
2013-11-17 22:26:41 +04:00
'rest_framework.authentication.SessionAuthentication',
'rest_framework.authentication.BasicAuthentication'
)
</code></pre>
2015-11-04 17:59:23 +03:00
<h4 id="default_permission_classes"><a class="toclink" href="#default_permission_classes">DEFAULT_PERMISSION_CLASSES</a></h4>
2014-11-25 19:04:38 +03:00
<p>A list or tuple of permission classes, that determines the default set of permissions checked at the start of a view. Permission must be granted by every class in the list.</p>
2013-11-17 22:26:41 +04:00
<p>Default:</p>
2014-11-25 19:04:38 +03:00
<pre><code>(
2013-11-17 22:26:41 +04:00
'rest_framework.permissions.AllowAny',
)
</code></pre>
2015-11-04 17:59:23 +03:00
<h4 id="default_throttle_classes"><a class="toclink" href="#default_throttle_classes">DEFAULT_THROTTLE_CLASSES</a></h4>
2013-11-17 22:26:41 +04:00
<p>A list or tuple of throttle classes, that determines the default set of throttles checked at the start of a view.</p>
<p>Default: <code>()</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="default_content_negotiation_class"><a class="toclink" href="#default_content_negotiation_class">DEFAULT_CONTENT_NEGOTIATION_CLASS</a></h4>
2013-11-17 22:26:41 +04:00
<p>A content negotiation class, that determines how a renderer is selected for the response, given an incoming request.</p>
<p>Default: <code>'rest_framework.negotiation.DefaultContentNegotiation'</code></p>
<h4 id="default_schema_class"><a class="toclink" href="#default_schema_class">DEFAULT_SCHEMA_CLASS</a></h4>
<p>A view inspector class that will be used for schema generation.</p>
<p>Default: <code>'rest_framework.schemas.AutoSchema'</code></p>
2013-11-17 22:26:41 +04:00
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="generic-view-settings"><a class="toclink" href="#generic-view-settings">Generic view settings</a></h2>
<p><em>The following settings control the behavior of the generic class-based views.</em></p>
2015-11-04 17:59:23 +03:00
<h4 id="default_pagination_serializer_class"><a class="toclink" href="#default_pagination_serializer_class">DEFAULT_PAGINATION_SERIALIZER_CLASS</a></h4>
2016-03-14 10:52:29 +03:00
<hr />
<p><strong>This setting has been removed.</strong></p>
<p>The pagination API does not use serializers to determine the output format, and
you'll need to instead override the `get_paginated_response method on a
pagination class in order to specify how the output format is controlled.</p>
<hr />
2015-11-04 17:59:23 +03:00
<h4 id="default_filter_backends"><a class="toclink" href="#default_filter_backends">DEFAULT_FILTER_BACKENDS</a></h4>
2013-11-17 22:26:41 +04:00
<p>A list of filter backend classes that should be used for generic filtering.
If set to <code>None</code> then generic filtering is disabled.</p>
2015-11-04 17:59:23 +03:00
<h4 id="paginate_by"><a class="toclink" href="#paginate_by">PAGINATE_BY</a></h4>
2016-03-14 10:52:29 +03:00
<hr />
<p><strong>This setting has been removed.</strong></p>
<p>See the pagination documentation for further guidance on <a href="../pagination/#modifying-the-pagination-style">setting the pagination style</a>.</p>
<hr />
<h4 id="page_size"><a class="toclink" href="#page_size">PAGE_SIZE</a></h4>
2013-11-17 22:26:41 +04:00
<p>The default page size to use for pagination. If set to <code>None</code>, pagination is disabled by default.</p>
<p>Default: <code>None</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="paginate_by_param"><a class="toclink" href="#paginate_by_param">PAGINATE_BY_PARAM</a></h4>
2015-08-06 16:31:52 +03:00
<hr />
2016-03-14 10:52:29 +03:00
<p><strong>This setting has been removed.</strong></p>
2015-08-06 16:31:52 +03:00
<p>See the pagination documentation for further guidance on <a href="../pagination/#modifying-the-pagination-style">setting the pagination style</a>.</p>
<hr />
2015-11-04 17:59:23 +03:00
<h4 id="max_paginate_by"><a class="toclink" href="#max_paginate_by">MAX_PAGINATE_BY</a></h4>
2015-08-06 16:31:52 +03:00
<hr />
<p><strong>This setting has been removed.</strong></p>
2015-08-06 16:31:52 +03:00
<p>See the pagination documentation for further guidance on <a href="../pagination/#modifying-the-pagination-style">setting the pagination style</a>.</p>
<hr />
2015-11-04 17:59:23 +03:00
<h3 id="search_param"><a class="toclink" href="#search_param">SEARCH_PARAM</a></h3>
2014-11-25 19:04:38 +03:00
<p>The name of a query parameter, which can be used to specify the search term used by <code>SearchFilter</code>.</p>
2014-03-17 12:35:23 +04:00
<p>Default: <code>search</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="ordering_param"><a class="toclink" href="#ordering_param">ORDERING_PARAM</a></h4>
2014-11-25 19:04:38 +03:00
<p>The name of a query parameter, which can be used to specify the ordering of results returned by <code>OrderingFilter</code>.</p>
2014-03-17 12:35:23 +04:00
<p>Default: <code>ordering</code></p>
2013-11-17 22:26:41 +04:00
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="versioning-settings"><a class="toclink" href="#versioning-settings">Versioning settings</a></h2>
<h4 id="default_version"><a class="toclink" href="#default_version">DEFAULT_VERSION</a></h4>
2015-03-06 15:05:16 +03:00
<p>The value that should be used for <code>request.version</code> when no versioning information is present.</p>
<p>Default: <code>None</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="allowed_versions"><a class="toclink" href="#allowed_versions">ALLOWED_VERSIONS</a></h4>
2015-03-06 15:05:16 +03:00
<p>If set, this value will restrict the set of versions that may be returned by the versioning scheme, and will raise an error if the provided version if not in this set.</p>
<p>Default: <code>None</code></p>
<h4 id="version_param"><a class="toclink" href="#version_param">VERSION_PARAM</a></h4>
2015-03-06 15:05:16 +03:00
<p>The string that should used for any versioning parameters, such as in the media type or URL query parameters.</p>
<p>Default: <code>'version'</code></p>
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="authentication-settings"><a class="toclink" href="#authentication-settings">Authentication settings</a></h2>
2013-11-17 22:26:41 +04:00
<p><em>The following settings control the behavior of unauthenticated requests.</em></p>
2015-11-04 17:59:23 +03:00
<h4 id="unauthenticated_user"><a class="toclink" href="#unauthenticated_user">UNAUTHENTICATED_USER</a></h4>
<p>The class that should be used to initialize <code>request.user</code> for unauthenticated requests.
(If removing authentication entirely, e.g. by removing <code>django.contrib.auth</code> from
<code>INSTALLED_APPS</code>, set <code>UNAUTHENTICATED_USER</code> to <code>None</code>.)</p>
2013-11-17 22:26:41 +04:00
<p>Default: <code>django.contrib.auth.models.AnonymousUser</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="unauthenticated_token"><a class="toclink" href="#unauthenticated_token">UNAUTHENTICATED_TOKEN</a></h4>
2013-11-17 22:26:41 +04:00
<p>The class that should be used to initialize <code>request.auth</code> for unauthenticated requests.</p>
<p>Default: <code>None</code></p>
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="test-settings"><a class="toclink" href="#test-settings">Test settings</a></h2>
2013-11-17 22:26:41 +04:00
<p><em>The following settings control the behavior of APIRequestFactory and APIClient</em></p>
2015-11-04 17:59:23 +03:00
<h4 id="test_request_default_format"><a class="toclink" href="#test_request_default_format">TEST_REQUEST_DEFAULT_FORMAT</a></h4>
2013-11-17 22:26:41 +04:00
<p>The default format that should be used when making test requests.</p>
<p>This should match up with the format of one of the renderer classes in the <code>TEST_REQUEST_RENDERER_CLASSES</code> setting.</p>
<p>Default: <code>'multipart'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="test_request_renderer_classes"><a class="toclink" href="#test_request_renderer_classes">TEST_REQUEST_RENDERER_CLASSES</a></h4>
2013-11-17 22:26:41 +04:00
<p>The renderer classes that are supported when building test requests.</p>
<p>The format of any of these renderer classes may be used when constructing a test request, for example: <code>client.post('/users', {'username': 'jamie'}, format='json')</code></p>
<p>Default:</p>
2014-11-25 19:04:38 +03:00
<pre><code>(
2013-11-17 22:26:41 +04:00
'rest_framework.renderers.MultiPartRenderer',
'rest_framework.renderers.JSONRenderer'
)
</code></pre>
<hr />
<h2 id="schema-generation-controls"><a class="toclink" href="#schema-generation-controls">Schema generation controls</a></h2>
<h4 id="schema_coerce_path_pk"><a class="toclink" href="#schema_coerce_path_pk">SCHEMA_COERCE_PATH_PK</a></h4>
<p>If set, this maps the <code>'pk'</code> identifier in the URL conf onto the actual field
name when generating a schema path parameter. Typically this will be <code>'id'</code>.
This gives a more suitable representation as "primary key" is an implementation
detail, whereas "identifier" is a more general concept.</p>
<p>Default: <code>True</code></p>
<h4 id="schema_coerce_method_names"><a class="toclink" href="#schema_coerce_method_names">SCHEMA_COERCE_METHOD_NAMES</a></h4>
<p>If set, this is used to map internal viewset method names onto external action
names used in the schema generation. This allows us to generate names that
are more suitable for an external representation than those that are used
internally in the codebase.</p>
<p>Default: <code>{'retrieve': 'read', 'destroy': 'delete'}</code></p>
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="content-type-controls"><a class="toclink" href="#content-type-controls">Content type controls</a></h2>
<h4 id="url_format_override"><a class="toclink" href="#url_format_override">URL_FORMAT_OVERRIDE</a></h4>
2015-10-28 14:35:39 +03:00
<p>The name of a URL parameter that may be used to override the default content negotiation <code>Accept</code> header behavior, by using a <code>format=…</code> query parameter in the request URL.</p>
<p>For example: <code>http://example.com/organizations/?format=csv</code></p>
<p>If the value of this setting is <code>None</code> then URL format overrides will be disabled.</p>
<p>Default: <code>'format'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="format_suffix_kwarg"><a class="toclink" href="#format_suffix_kwarg">FORMAT_SUFFIX_KWARG</a></h4>
2015-10-28 14:35:39 +03:00
<p>The name of a parameter in the URL conf that may be used to provide a format suffix. This setting is applied when using <code>format_suffix_patterns</code> to include suffixed URL patterns.</p>
<p>For example: <code>http://example.com/organizations.csv/</code></p>
2013-11-17 22:26:41 +04:00
<p>Default: <code>'format'</code></p>
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="date-and-time-formatting"><a class="toclink" href="#date-and-time-formatting">Date and time formatting</a></h2>
2013-11-17 22:26:41 +04:00
<p><em>The following settings are used to control how date and time representations may be parsed and rendered.</em></p>
2015-11-04 17:59:23 +03:00
<h4 id="datetime_format"><a class="toclink" href="#datetime_format">DATETIME_FORMAT</a></h4>
2013-11-17 22:26:41 +04:00
<p>A format string that should be used by default for rendering the output of <code>DateTimeField</code> serializer fields. If <code>None</code>, then <code>DateTimeField</code> serializer fields will return Python <code>datetime</code> objects, and the datetime encoding will be determined by the renderer.</p>
<p>May be any of <code>None</code>, <code>'iso-8601'</code> or a Python <a href="https://docs.python.org/3/library/time.html#time.strftime">strftime format</a> string.</p>
2014-11-25 19:04:38 +03:00
<p>Default: <code>'iso-8601'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="datetime_input_formats"><a class="toclink" href="#datetime_input_formats">DATETIME_INPUT_FORMATS</a></h4>
2013-11-17 22:26:41 +04:00
<p>A list of format strings that should be used by default for parsing inputs to <code>DateTimeField</code> serializer fields.</p>
<p>May be a list including the string <code>'iso-8601'</code> or Python <a href="https://docs.python.org/3/library/time.html#time.strftime">strftime format</a> strings.</p>
2013-11-17 22:26:41 +04:00
<p>Default: <code>['iso-8601']</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="date_format"><a class="toclink" href="#date_format">DATE_FORMAT</a></h4>
2013-11-17 22:26:41 +04:00
<p>A format string that should be used by default for rendering the output of <code>DateField</code> serializer fields. If <code>None</code>, then <code>DateField</code> serializer fields will return Python <code>date</code> objects, and the date encoding will be determined by the renderer.</p>
<p>May be any of <code>None</code>, <code>'iso-8601'</code> or a Python <a href="https://docs.python.org/3/library/time.html#time.strftime">strftime format</a> string.</p>
2014-11-25 19:04:38 +03:00
<p>Default: <code>'iso-8601'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="date_input_formats"><a class="toclink" href="#date_input_formats">DATE_INPUT_FORMATS</a></h4>
2013-11-17 22:26:41 +04:00
<p>A list of format strings that should be used by default for parsing inputs to <code>DateField</code> serializer fields.</p>
<p>May be a list including the string <code>'iso-8601'</code> or Python <a href="https://docs.python.org/3/library/time.html#time.strftime">strftime format</a> strings.</p>
2013-11-17 22:26:41 +04:00
<p>Default: <code>['iso-8601']</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="time_format"><a class="toclink" href="#time_format">TIME_FORMAT</a></h4>
2013-11-17 22:26:41 +04:00
<p>A format string that should be used by default for rendering the output of <code>TimeField</code> serializer fields. If <code>None</code>, then <code>TimeField</code> serializer fields will return Python <code>time</code> objects, and the time encoding will be determined by the renderer.</p>
<p>May be any of <code>None</code>, <code>'iso-8601'</code> or a Python <a href="https://docs.python.org/3/library/time.html#time.strftime">strftime format</a> string.</p>
2014-11-25 19:04:38 +03:00
<p>Default: <code>'iso-8601'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="time_input_formats"><a class="toclink" href="#time_input_formats">TIME_INPUT_FORMATS</a></h4>
2013-11-17 22:26:41 +04:00
<p>A list of format strings that should be used by default for parsing inputs to <code>TimeField</code> serializer fields.</p>
<p>May be a list including the string <code>'iso-8601'</code> or Python <a href="https://docs.python.org/3/library/time.html#time.strftime">strftime format</a> strings.</p>
2013-11-17 22:26:41 +04:00
<p>Default: <code>['iso-8601']</code></p>
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="encodings"><a class="toclink" href="#encodings">Encodings</a></h2>
<h4 id="unicode_json"><a class="toclink" href="#unicode_json">UNICODE_JSON</a></h4>
2014-11-25 19:04:38 +03:00
<p>When set to <code>True</code>, JSON responses will allow unicode characters in responses. For example:</p>
<pre><code>{"unicode black star":"★"}
</code></pre>
<p>When set to <code>False</code>, JSON responses will escape non-ascii characters, like so:</p>
<pre><code>{"unicode black star":"\u2605"}
</code></pre>
<p>Both styles conform to <a href="https://www.ietf.org/rfc/rfc4627.txt">RFC 4627</a>, and are syntactically valid JSON. The unicode style is preferred as being more user-friendly when inspecting API responses.</p>
2014-11-25 19:04:38 +03:00
<p>Default: <code>True</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="compact_json"><a class="toclink" href="#compact_json">COMPACT_JSON</a></h4>
2014-11-25 19:04:38 +03:00
<p>When set to <code>True</code>, JSON responses will return compact representations, with no spacing after <code>':'</code> and <code>','</code> characters. For example:</p>
<pre><code>{"is_admin":false,"email":"jane@example"}
</code></pre>
<p>When set to <code>False</code>, JSON responses will return slightly more verbose representations, like so:</p>
<pre><code>{"is_admin": false, "email": "jane@example"}
</code></pre>
<p>The default style is to return minified responses, in line with <a href="https://github.com/interagent/http-api-design#keep-json-minified-in-all-responses">Heroku's API design guidelines</a>.</p>
<p>Default: <code>True</code></p>
<h4 id="strict_json"><a class="toclink" href="#strict_json">STRICT_JSON</a></h4>
<p>When set to <code>True</code>, JSON rendering and parsing will only observe syntactically valid JSON, raising an exception for the extended float values (<code>nan</code>, <code>inf</code>, <code>-inf</code>) accepted by Python's <code>json</code> module. This is the recommended setting, as these values are not generally supported. e.g., neither Javascript's <code>JSON.Parse</code> nor PostgreSQL's JSON data type accept these values.</p>
<p>When set to <code>False</code>, JSON rendering and parsing will be permissive. However, these values are still invalid and will need to be specially handled in your code.</p>
<p>Default: <code>True</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="coerce_decimal_to_string"><a class="toclink" href="#coerce_decimal_to_string">COERCE_DECIMAL_TO_STRING</a></h4>
2014-11-25 19:04:38 +03:00
<p>When returning decimal objects in API representations that do not support a native decimal type, it is normally best to return the value as a string. This avoids the loss of precision that occurs with binary floating point implementations.</p>
<p>When set to <code>True</code>, the serializer <code>DecimalField</code> class will return strings instead of <code>Decimal</code> objects. When set to <code>False</code>, serializers will return <code>Decimal</code> objects, which the default JSON encoder will return as floats.</p>
<p>Default: <code>True</code></p>
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="view-names-and-descriptions"><a class="toclink" href="#view-names-and-descriptions">View names and descriptions</a></h2>
2013-11-17 22:26:41 +04:00
<p><strong>The following settings are used to generate the view names and descriptions, as used in responses to <code>OPTIONS</code> requests, and as used in the browsable API.</strong></p>
2015-11-04 17:59:23 +03:00
<h4 id="view_name_function"><a class="toclink" href="#view_name_function">VIEW_NAME_FUNCTION</a></h4>
2013-11-17 22:26:41 +04:00
<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>
2014-11-25 19:04:38 +03:00
<pre><code>view_name(cls, suffix=None)
2013-11-17 22:26:41 +04:00
</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>
</ul>
<p>Default: <code>'rest_framework.views.get_view_name'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="view_description_function"><a class="toclink" href="#view_description_function">VIEW_DESCRIPTION_FUNCTION</a></h4>
2013-11-17 22:26:41 +04:00
<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>
2014-11-25 19:04:38 +03:00
<pre><code>view_description(cls, html=False)
2013-11-17 22:26:41 +04:00
</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>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>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>
<h4 id="html_select_cutoff"><a class="toclink" href="#html_select_cutoff">HTML_SELECT_CUTOFF</a></h4>
<p>Global setting for the <code>html_cutoff</code> value. Must be an integer.</p>
<p>Default: 1000</p>
<h4 id="html_select_cutoff_text"><a class="toclink" href="#html_select_cutoff_text">HTML_SELECT_CUTOFF_TEXT</a></h4>
<p>A string representing a global setting for <code>html_cutoff_text</code>.</p>
<p>Default: <code>"More than {count} items..."</code></p>
2013-11-17 22:26:41 +04:00
<hr />
2015-11-04 17:59:23 +03:00
<h2 id="miscellaneous-settings"><a class="toclink" href="#miscellaneous-settings">Miscellaneous settings</a></h2>
<h4 id="exception_handler"><a class="toclink" href="#exception_handler">EXCEPTION_HANDLER</a></h4>
2013-11-17 22:26:41 +04:00
<p>A string representing the function that should be used when returning a response for any given exception. If the function returns <code>None</code>, a 500 error will be raised.</p>
<p>This setting can be changed to support error responses other than the default <code>{"detail": "Failure..."}</code> responses. For example, you can use it to provide API responses like <code>{"errors": [{"message": "Failure...", "code": ""} ...]}</code>.</p>
<p>This should be a function with the following signature:</p>
2015-03-06 15:05:16 +03:00
<pre><code>exception_handler(exc, context)
2013-11-17 22:26:41 +04:00
</code></pre>
<ul>
<li><code>exc</code>: The exception.</li>
</ul>
<p>Default: <code>'rest_framework.views.exception_handler'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="non_field_errors_key"><a class="toclink" href="#non_field_errors_key">NON_FIELD_ERRORS_KEY</a></h4>
2014-11-25 19:04:38 +03:00
<p>A string representing the key that should be used for serializer errors that do not refer to a specific field, but are instead general errors.</p>
<p>Default: <code>'non_field_errors'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="url_field_name"><a class="toclink" href="#url_field_name">URL_FIELD_NAME</a></h4>
2014-01-15 18:43:34 +04:00
<p>A string representing the key that should be used for the URL fields generated by <code>HyperlinkedModelSerializer</code>.</p>
<p>Default: <code>'url'</code></p>
2015-11-04 17:59:23 +03:00
<h4 id="num_proxies"><a class="toclink" href="#num_proxies">NUM_PROXIES</a></h4>
2014-08-28 20:33:56 +04:00
<p>An integer of 0 or more, that may be used to specify the number of application proxies that the API runs behind. This allows throttling to more accurately identify client IP addresses. If set to <code>None</code> then less strict IP matching will be used by the throttle classes.</p>
<p>Default: <code>None</code></p>
2015-06-04 17:37:22 +03:00
2015-06-23 14:05:53 +03:00
</div> <!--/span-->
</div> <!--/row-->
</div> <!--/.fluid-container-->
</div> <!--/.body content-->
2014-11-25 19:04:38 +03:00
<div id="push"></div>
2015-06-23 14:05:53 +03:00
</div> <!--/.wrapper -->
2013-11-17 22:26:41 +04:00
<footer class="span12">
2015-10-28 14:35:39 +03:00
<p>Documentation built with <a href="http://www.mkdocs.org/">MkDocs</a>.
2014-11-25 19:04:38 +03:00
</p>
2013-11-17 22:26:41 +04:00
</footer>
2014-11-25 19:04:38 +03:00
<!-- 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>
2016-05-26 13:48:39 +03:00
<script src="https://fund.django-rest-framework.org/sidebar_include.js"></script>
2015-06-04 17:37:22 +03:00
<script>var base_url = '../..';</script>
<script src="../../mkdocs/js/require.js"></script>
2014-12-11 12:55:10 +03:00
<script src="../../js/theme.js"></script>
2013-11-17 22:26:41 +04:00
2014-11-25 19:04:38 +03:00
<script>
var shiftWindow = function() {
scrollBy(0, -50)
};
2015-06-23 14:05:53 +03:00
2014-11-25 19:04:38 +03:00
if (location.hash) shiftWindow();
window.addEventListener("hashchange", shiftWindow);
2013-11-17 22:26:41 +04:00
2014-11-25 19:04:38 +03:00
$('.dropdown-menu').on('click touchstart', function(event) {
event.stopPropagation();
});
2015-06-23 14:05:53 +03:00
// Dynamically force sidenav/dropdown to no higher than browser window
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
2014-11-25 19:04:38 +03:00
$(function() {
$(window).resize(function() {
2015-06-23 14:05:53 +03:00
$('.side-nav, .dropdown-menu').css('max-height', window.innerHeight - 130);
2013-11-17 22:26:41 +04:00
});
2014-11-25 19:04:38 +03:00
});
</script>
</body>
</html>