mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-15 22:26:57 +03:00
768 lines
38 KiB
HTML
768 lines
38 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
<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/" />
|
|
<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>
|
|
#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/tomchristie/django-rest-framework/tree/master">GitHub</a>
|
|
<a class="repo-link btn btn-inverse btn-small " rel="prev" href="../../topics/documenting-your-api/">
|
|
Next <i class="icon-arrow-right icon-white"></i>
|
|
</a>
|
|
<a class="repo-link btn btn-inverse btn-small " rel="next" href="../testing/">
|
|
<i class="icon-arrow-left icon-white"></i> Previous
|
|
</a>
|
|
<a id="search_modal_show" class="repo-link btn btn-inverse btn-small" href="#mkdocs_search_modal" data-toggle="modal" data-target="#mkdocs_search_modal"><i class="icon-search icon-white"></i> Search</a>
|
|
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
<span class="icon-bar"></span>
|
|
</a>
|
|
<a class="brand" href="http://www.django-rest-framework.org">Django REST framework</a>
|
|
<div class="nav-collapse collapse">
|
|
|
|
<!-- 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 >
|
|
<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 class="active" >
|
|
<a href="./">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>
|
|
|
|
<li >
|
|
<a href="../../topics/third-party-resources/">Third Party Resources</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/contributing/">Contributing to REST framework</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/project-management/">Project management</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/3.0-announcement/">3.0 Announcement</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/3.1-announcement/">3.1 Announcement</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/3.2-announcement/">3.2 Announcement</a>
|
|
</li>
|
|
|
|
<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/kickstarter-announcement/">Kickstarter Announcement</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/mozilla-grant/">Mozilla Grant</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/funding/">Funding</a>
|
|
</li>
|
|
|
|
<li >
|
|
<a href="../../topics/release-notes/">Release Notes</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="#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>
|
|
|
|
<li>
|
|
<a href="#versioning-settings">Versioning settings</a>
|
|
</li>
|
|
|
|
<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>
|
|
|
|
<li>
|
|
<a href="#content-type-controls">Content type controls</a>
|
|
</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>
|
|
|
|
<li>
|
|
<a href="#miscellaneous-settings">Miscellaneous settings</a>
|
|
</li>
|
|
|
|
|
|
|
|
<div class="promo">
|
|
<hr/>
|
|
<div id="sidebarInclude">
|
|
</div>
|
|
</ul>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
<div id="main-content" class="span9">
|
|
|
|
|
|
|
|
<a class="github" href="https://github.com/tomchristie/django-rest-framework/tree/master/rest_framework/settings.py">
|
|
<span class="label label-info">settings.py</span>
|
|
</a>
|
|
|
|
|
|
|
|
<h1 id="settings"><a class="toclink" href="#settings">Settings</a></h1>
|
|
<blockquote>
|
|
<p>Namespaces are one honking great idea - let's do more of those!</p>
|
|
<p>— <a href="https://www.python.org/dev/peps/pep-0020/">The Zen of Python</a></p>
|
|
</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>
|
|
<pre><code>REST_FRAMEWORK = {
|
|
'DEFAULT_RENDERER_CLASSES': (
|
|
'rest_framework.renderers.JSONRenderer',
|
|
),
|
|
'DEFAULT_PARSER_CLASSES': (
|
|
'rest_framework.parsers.JSONParser',
|
|
)
|
|
}
|
|
</code></pre>
|
|
<h2 id="accessing-settings"><a class="toclink" href="#accessing-settings">Accessing settings</a></h2>
|
|
<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>
|
|
<pre><code>from rest_framework.settings import api_settings
|
|
|
|
print api_settings.DEFAULT_AUTHENTICATION_CLASSES
|
|
</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 />
|
|
<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>
|
|
<h4 id="default_renderer_classes"><a class="toclink" href="#default_renderer_classes">DEFAULT_RENDERER_CLASSES</a></h4>
|
|
<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>
|
|
<pre><code>(
|
|
'rest_framework.renderers.JSONRenderer',
|
|
'rest_framework.renderers.BrowsableAPIRenderer',
|
|
)
|
|
</code></pre>
|
|
<h4 id="default_parser_classes"><a class="toclink" href="#default_parser_classes">DEFAULT_PARSER_CLASSES</a></h4>
|
|
<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>
|
|
<p>Default:</p>
|
|
<pre><code>(
|
|
'rest_framework.parsers.JSONParser',
|
|
'rest_framework.parsers.FormParser',
|
|
'rest_framework.parsers.MultiPartParser'
|
|
)
|
|
</code></pre>
|
|
<h4 id="default_authentication_classes"><a class="toclink" href="#default_authentication_classes">DEFAULT_AUTHENTICATION_CLASSES</a></h4>
|
|
<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>
|
|
<pre><code>(
|
|
'rest_framework.authentication.SessionAuthentication',
|
|
'rest_framework.authentication.BasicAuthentication'
|
|
)
|
|
</code></pre>
|
|
<h4 id="default_permission_classes"><a class="toclink" href="#default_permission_classes">DEFAULT_PERMISSION_CLASSES</a></h4>
|
|
<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>
|
|
<p>Default:</p>
|
|
<pre><code>(
|
|
'rest_framework.permissions.AllowAny',
|
|
)
|
|
</code></pre>
|
|
<h4 id="default_throttle_classes"><a class="toclink" href="#default_throttle_classes">DEFAULT_THROTTLE_CLASSES</a></h4>
|
|
<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>
|
|
<h4 id="default_content_negotiation_class"><a class="toclink" href="#default_content_negotiation_class">DEFAULT_CONTENT_NEGOTIATION_CLASS</a></h4>
|
|
<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>
|
|
<hr />
|
|
<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>
|
|
<h4 id="default_pagination_serializer_class"><a class="toclink" href="#default_pagination_serializer_class">DEFAULT_PAGINATION_SERIALIZER_CLASS</a></h4>
|
|
<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 />
|
|
<h4 id="default_filter_backends"><a class="toclink" href="#default_filter_backends">DEFAULT_FILTER_BACKENDS</a></h4>
|
|
<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>
|
|
<h4 id="paginate_by"><a class="toclink" href="#paginate_by">PAGINATE_BY</a></h4>
|
|
<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>
|
|
<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>
|
|
<h4 id="paginate_by_param"><a class="toclink" href="#paginate_by_param">PAGINATE_BY_PARAM</a></h4>
|
|
<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="max_paginate_by"><a class="toclink" href="#max_paginate_by">MAX_PAGINATE_BY</a></h4>
|
|
<hr />
|
|
<p><strong>This setting is pending deprecation.</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 />
|
|
<h3 id="search_param"><a class="toclink" href="#search_param">SEARCH_PARAM</a></h3>
|
|
<p>The name of a query parameter, which can be used to specify the search term used by <code>SearchFilter</code>.</p>
|
|
<p>Default: <code>search</code></p>
|
|
<h4 id="ordering_param"><a class="toclink" href="#ordering_param">ORDERING_PARAM</a></h4>
|
|
<p>The name of a query parameter, which can be used to specify the ordering of results returned by <code>OrderingFilter</code>.</p>
|
|
<p>Default: <code>ordering</code></p>
|
|
<hr />
|
|
<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>
|
|
<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>
|
|
<h4 id="allowed_versions"><a class="toclink" href="#allowed_versions">ALLOWED_VERSIONS</a></h4>
|
|
<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>
|
|
<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 />
|
|
<h2 id="authentication-settings"><a class="toclink" href="#authentication-settings">Authentication settings</a></h2>
|
|
<p><em>The following settings control the behavior of unauthenticated requests.</em></p>
|
|
<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.</p>
|
|
<p>Default: <code>django.contrib.auth.models.AnonymousUser</code></p>
|
|
<h4 id="unauthenticated_token"><a class="toclink" href="#unauthenticated_token">UNAUTHENTICATED_TOKEN</a></h4>
|
|
<p>The class that should be used to initialize <code>request.auth</code> for unauthenticated requests.</p>
|
|
<p>Default: <code>None</code></p>
|
|
<hr />
|
|
<h2 id="test-settings"><a class="toclink" href="#test-settings">Test settings</a></h2>
|
|
<p><em>The following settings control the behavior of APIRequestFactory and APIClient</em></p>
|
|
<h4 id="test_request_default_format"><a class="toclink" href="#test_request_default_format">TEST_REQUEST_DEFAULT_FORMAT</a></h4>
|
|
<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>
|
|
<h4 id="test_request_renderer_classes"><a class="toclink" href="#test_request_renderer_classes">TEST_REQUEST_RENDERER_CLASSES</a></h4>
|
|
<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>
|
|
<pre><code>(
|
|
'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 />
|
|
<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>
|
|
<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>
|
|
<h4 id="format_suffix_kwarg"><a class="toclink" href="#format_suffix_kwarg">FORMAT_SUFFIX_KWARG</a></h4>
|
|
<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>
|
|
<p>Default: <code>'format'</code></p>
|
|
<hr />
|
|
<h2 id="date-and-time-formatting"><a class="toclink" href="#date-and-time-formatting">Date and time formatting</a></h2>
|
|
<p><em>The following settings are used to control how date and time representations may be parsed and rendered.</em></p>
|
|
<h4 id="datetime_format"><a class="toclink" href="#datetime_format">DATETIME_FORMAT</a></h4>
|
|
<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>
|
|
<p>Default: <code>'iso-8601'</code></p>
|
|
<h4 id="datetime_input_formats"><a class="toclink" href="#datetime_input_formats">DATETIME_INPUT_FORMATS</a></h4>
|
|
<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>
|
|
<p>Default: <code>['iso-8601']</code></p>
|
|
<h4 id="date_format"><a class="toclink" href="#date_format">DATE_FORMAT</a></h4>
|
|
<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>
|
|
<p>Default: <code>'iso-8601'</code></p>
|
|
<h4 id="date_input_formats"><a class="toclink" href="#date_input_formats">DATE_INPUT_FORMATS</a></h4>
|
|
<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>
|
|
<p>Default: <code>['iso-8601']</code></p>
|
|
<h4 id="time_format"><a class="toclink" href="#time_format">TIME_FORMAT</a></h4>
|
|
<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>
|
|
<p>Default: <code>'iso-8601'</code></p>
|
|
<h4 id="time_input_formats"><a class="toclink" href="#time_input_formats">TIME_INPUT_FORMATS</a></h4>
|
|
<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>
|
|
<p>Default: <code>['iso-8601']</code></p>
|
|
<hr />
|
|
<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>
|
|
<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="http://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>
|
|
<p>Default: <code>True</code></p>
|
|
<h4 id="compact_json"><a class="toclink" href="#compact_json">COMPACT_JSON</a></h4>
|
|
<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="coerce_decimal_to_string"><a class="toclink" href="#coerce_decimal_to_string">COERCE_DECIMAL_TO_STRING</a></h4>
|
|
<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 />
|
|
<h2 id="view-names-and-descriptions"><a class="toclink" href="#view-names-and-descriptions">View names and descriptions</a></h2>
|
|
<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>
|
|
<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)
|
|
</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>
|
|
<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)
|
|
</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>
|
|
<hr />
|
|
<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>
|
|
<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>
|
|
<pre><code>exception_handler(exc, context)
|
|
</code></pre>
|
|
<ul>
|
|
<li><code>exc</code>: The exception.</li>
|
|
</ul>
|
|
<p>Default: <code>'rest_framework.views.exception_handler'</code></p>
|
|
<h4 id="non_field_errors_key"><a class="toclink" href="#non_field_errors_key">NON_FIELD_ERRORS_KEY</a></h4>
|
|
<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>
|
|
<h4 id="url_field_name"><a class="toclink" href="#url_field_name">URL_FIELD_NAME</a></h4>
|
|
<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>
|
|
<h4 id="num_proxies"><a class="toclink" href="#num_proxies">NUM_PROXIES</a></h4>
|
|
<p>An integer of 0 or more, that may be used to specify the number of application proxies that the API runs behind. This allows throttling to more accurately identify client IP addresses. If set to <code>None</code> then less strict IP matching will be used by the throttle classes.</p>
|
|
<p>Default: <code>None</code></p>
|
|
|
|
|
|
</div> <!--/span-->
|
|
</div> <!--/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> |