mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-12-04 07:24:03 +03:00
Latest docs build
This commit is contained in:
parent
679a50d09e
commit
25ae57d20f
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
@ -95,7 +95,7 @@
|
|||
<li class="main"><a href="#authentication">Authentication</a></li>
|
||||
<li><a href="#how-authentication-is-determined">How authentication is determined</a></li>
|
||||
<li><a href="#setting-the-authentication-policy">Setting the authentication policy</a></li>
|
||||
<li><a href="#userbasicauthentication">UserBasicAuthentication</a></li>
|
||||
<li><a href="#basicauthentication">BasicAuthentication</a></li>
|
||||
<li><a href="#tokenauthentication">TokenAuthentication</a></li>
|
||||
<li><a href="#oauthauthentication">OAuthAuthentication</a></li>
|
||||
<li><a href="#sessionauthentication">SessionAuthentication</a></li>
|
||||
|
@ -118,7 +118,7 @@
|
|||
<p>The <code>request.user</code> property will typically be set to an instance of the <code>contrib.auth</code> package's <code>User</code> class.</p>
|
||||
<p>The <code>request.auth</code> property is used for any additional authentication information, for example, it may be used to represent an authentication token that the request was signed with.</p>
|
||||
<h2 id="how-authentication-is-determined">How authentication is determined</h2>
|
||||
<p>Authentication is always set as a list of classes. REST framework will attempt to authenticate with each class in the list, and will set <code>request.user</code> and <code>request.auth</code> using the return value of the first class that successfully authenticates.</p>
|
||||
<p>The authentication policy is always defined as a list of classes. REST framework will attempt to authenticate with each class in the list, and will set <code>request.user</code> and <code>request.auth</code> using the return value of the first class that successfully authenticates.</p>
|
||||
<p>If no class authenticates, <code>request.user</code> will be set to an instance of <code>django.contrib.auth.models.AnonymousUser</code>, and <code>request.auth</code> will be set to <code>None</code>.</p>
|
||||
<p>The value of <code>request.user</code> and <code>request.auth</code> for unauthenticated requests can be modified using the <code>UNAUTHENTICATED_USER</code> and <code>UNAUTHENTICATED_TOKEN</code> settings.</p>
|
||||
<h2 id="setting-the-authentication-policy">Setting the authentication policy</h2>
|
||||
|
@ -153,26 +153,32 @@ def example_view(request, format=None):
|
|||
}
|
||||
return Response(content)
|
||||
</code></pre>
|
||||
<h2 id="userbasicauthentication">UserBasicAuthentication</h2>
|
||||
<p>This policy uses <a href="http://tools.ietf.org/html/rfc2617">HTTP Basic Authentication</a>, signed against a user's username and password. User basic authentication is generally only appropriate for testing.</p>
|
||||
<p><strong>Note:</strong> If you run <code>UserBasicAuthentication</code> in production your API should be <code>https</code> only. You should also ensure that your API clients will always re-request the username and password at login, and will never store those details to persistent storage.</p>
|
||||
<p>If successfully authenticated, <code>UserBasicAuthentication</code> provides the following credentials.</p>
|
||||
<h2 id="basicauthentication">BasicAuthentication</h2>
|
||||
<p>This policy uses <a href="http://tools.ietf.org/html/rfc2617">HTTP Basic Authentication</a>, signed against a user's username and password. Basic authentication is generally only appropriate for testing.</p>
|
||||
<p>If successfully authenticated, <code>BasicAuthentication</code> provides the following credentials.</p>
|
||||
<ul>
|
||||
<li><code>request.user</code> will be a <code>django.contrib.auth.models.User</code> instance.</li>
|
||||
<li><code>request.auth</code> will be <code>None</code>.</li>
|
||||
</ul>
|
||||
<p><strong>Note:</strong> If you use <code>BasicAuthentication</code> in production you must ensure that your API is only available over <code>https</code> only. You should also ensure that your API clients will always re-request the username and password at login, and will never store those details to persistent storage.</p>
|
||||
<h2 id="tokenauthentication">TokenAuthentication</h2>
|
||||
<p>This policy uses simple token-based HTTP Authentication. Token basic authentication is appropriate for client-server setups, such as native desktop and mobile clients.</p>
|
||||
<p>The token key should be passed in as a string to the "Authorization" HTTP header. For example:</p>
|
||||
<pre class="prettyprint lang-py"><code>curl http://my.api.org/ -X POST -H "Authorization: 0123456789abcdef0123456789abcdef"
|
||||
<p>This policy uses a simple token-based HTTP Authentication scheme. Token authentication is appropriate for client-server setups, such as native desktop and mobile clients.</p>
|
||||
<p>To use the <code>TokenAuthentication</code> policy, include <code>djangorestframework.authtoken</code> in your <code>INSTALLED_APPS</code> setting.</p>
|
||||
<p>You'll also need to create tokens for your users.</p>
|
||||
<pre class="prettyprint lang-py"><code>from djangorestframework.authtoken.models import Token
|
||||
|
||||
token = Token.objects.create(user=...)
|
||||
print token.key
|
||||
</code></pre>
|
||||
<p>For clients to authenticate, the token key should be included in the <code>Authorization</code> HTTP header. The key should be prefixed by the string literal "Token", with whitespace seperating the two strings. For example:</p>
|
||||
<pre class="prettyprint lang-py"><code>Authorization: Token 9944b09199c62bcf9418ad846dd0e4bbdfc6ee4b
|
||||
</code></pre>
|
||||
<p><strong>Note:</strong> If you run <code>TokenAuthentication</code> in production your API should be <code>https</code> only.</p>
|
||||
<p>If successfully authenticated, <code>TokenAuthentication</code> provides the following credentials.</p>
|
||||
<ul>
|
||||
<li><code>request.user</code> will be a <code>django.contrib.auth.models.User</code> instance.</li>
|
||||
<li><code>request.auth</code> will be a <code>djangorestframework.tokenauth.models.BasicToken</code> instance.</li>
|
||||
</ul>
|
||||
<p>To use the <code>TokenAuthentication</code> policy, you must have a token model. Django REST Framework comes with a minimal default token model. To use it, include <code>djangorestframework.tokenauth</code> in your installed applications and sync your database. To use your own token model, subclass the <code>djangorestframework.tokenauth.TokenAuthentication</code> class and specify a <code>model</code> attribute that references your custom token model. The token model must provide <code>user</code>, <code>key</code>, and <code>revoked</code> attributes. Refer to the <code>djangorestframework.tokenauth.models.BasicToken</code> model as an example.</p>
|
||||
<p><strong>Note:</strong> If you use <code>TokenAuthentication</code> in production you must ensure that your API is only available over <code>https</code> only.</p>
|
||||
<h2 id="oauthauthentication">OAuthAuthentication</h2>
|
||||
<p>This policy uses the <a href="http://oauth.net/2/">OAuth 2.0</a> protocol to authenticate requests. OAuth is appropriate for server-server setups, such as when you want to allow a third-party service to access your API on a user's behalf.</p>
|
||||
<p>If successfully authenticated, <code>OAuthAuthentication</code> provides the following credentials.</p>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
@ -116,8 +116,10 @@
|
|||
<p>Together with <a href="authentication">authentication</a> and <a href="throttling">throttling</a>, permissions determine wheter a request should be granted or denied access.</p>
|
||||
<p>Permission checks are always run at the very start of the view, before any other code is allowed to proceed. Permission checks will typically use the authentication information in the <code>request.user</code> and <code>request.auth</code> properties to determine if the incoming request should be permitted.</p>
|
||||
<h2 id="how-permissions-are-determined">How permissions are determined</h2>
|
||||
<p>Permissions in REST framework are always defined as a list of permission classes. Before running the main body of the view each permission in the list is checked.</p>
|
||||
<p>If any permission check fails an <code>exceptions.PermissionDenied</code> exception will be raised, and the main body of the view will not run.</p>
|
||||
<p>Permissions in REST framework are always defined as a list of permission classes.<br />
|
||||
</p>
|
||||
<p>Before running the main body of the view each permission in the list is checked.
|
||||
If any permission check fails an <code>exceptions.PermissionDenied</code> exception will be raised, and the main body of the view will not run.</p>
|
||||
<h2 id="object-level-permissions">Object level permissions</h2>
|
||||
<p>REST framework permissions also support object-level permissioning. Object level permissions are used to determine if a user should be allowed to act on a particular object, which will typically be a model instance.</p>
|
||||
<p>Object level permissions are run by REST framework's generic views when <code>.get_object()</code> is called. As with view level permissions, an <code>exceptions.PermissionDenied</code> exception will be raised if the user is not allowed to act on the given object.</p>
|
||||
|
@ -166,7 +168,7 @@ def example_view(request, format=None):
|
|||
</ul>
|
||||
<p>The default behaviour can also be overridden to support custom model permissions. For example, you might want to include a <code>view</code> model permission for <code>GET</code> requests.</p>
|
||||
<p>To use custom model permissions, override <code>DjangoModelPermissions</code> and set the <code>.perms_map</code> property. Refer to the source code for details.</p>
|
||||
<p>The <code>DjangoModelPermissions</code> class also supports object-level permissions. Third-party authorization backends such as <a href="https://github.com/lukaszb/django-guardian">django-guardian</a> should work just fine with <code>DjangoModelPermissions</code> without any custom configuration required.</p>
|
||||
<p>The <code>DjangoModelPermissions</code> class also supports object-level permissions. Third-party authorization backends such as <a href="https://github.com/lukaszb/django-guardian">django-guardian</a> that provide object-level permissions should work just fine with <code>DjangoModelPermissions</code> without any custom configuration required.</p>
|
||||
<h2 id="custom-permissions">Custom permissions</h2>
|
||||
<p>To implement a custom permission, override <code>BasePermission</code> and implement the <code>.check_permission(self, request, obj=None)</code> method.</p>
|
||||
<p>The method should return <code>True</code> if the request should be granted access, and <code>False</code> otherwise.</p>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
@ -93,8 +93,11 @@
|
|||
<div id="table-of-contents" class="well affix span3">
|
||||
<ul class="nav nav-list side-nav">
|
||||
<li class="main"><a href="#throttling">Throttling</a></li>
|
||||
<li><a href="#peruserthrottle">PerUserThrottle</a></li>
|
||||
<li><a href="#perviewthrottle">PerViewThrottle</a></li>
|
||||
<li><a href="#how-throttling-is-determined">How throttling is determined</a></li>
|
||||
<li><a href="#setting-the-throttling-policy">Setting the throttling policy</a></li>
|
||||
<li><a href="#anonthrottle">AnonThrottle</a></li>
|
||||
<li><a href="#userthrottle">UserThrottle</a></li>
|
||||
<li><a href="#scopedthrottle">ScopedThrottle</a></li>
|
||||
<li><a href="#custom-throttles">Custom throttles</a></li>
|
||||
|
||||
</ul>
|
||||
|
@ -108,8 +111,52 @@
|
|||
<p>HTTP/1.1 420 Enhance Your Calm</p>
|
||||
<p><a href="https://dev.twitter.com/docs/error-codes-responses">Twitter API rate limiting response</a></p>
|
||||
</blockquote>
|
||||
<h2 id="peruserthrottle">PerUserThrottle</h2>
|
||||
<h2 id="perviewthrottle">PerViewThrottle</h2>
|
||||
<p>Throttling is similar to <a href="permissions">permissions</a>, in that it determines if a request should be authorized. Throttles indicate a temporary state, and are used to control the rate of requests that clients can make to an API.</p>
|
||||
<p>As with permissions, multiple throttles may be used. Your API might have a restrictive throttle for unauthenticated requests, and a less restrictive throttle for authenticated requests.</p>
|
||||
<p>Another scenario where you might want to use multiple throttles would be if you need to impose different constraints on different parts of the API, due ato some services being particularly resource-intensive.</p>
|
||||
<p>Throttles do not necessarily only refer to rate-limiting requests. For example a storage service might also need to throttle against bandwidth.</p>
|
||||
<h2 id="how-throttling-is-determined">How throttling is determined</h2>
|
||||
<p>As with permissions and authentication, throttling in REST framework is always defined as a list of classes.</p>
|
||||
<p>Before running the main body of the view each throttle in the list is checked.
|
||||
If any throttle check fails an <code>exceptions.Throttled</code> exception will be raised, and the main body of the view will not run.</p>
|
||||
<h2 id="setting-the-throttling-policy">Setting the throttling policy</h2>
|
||||
<p>The default throttling policy may be set globally, using the <code>DEFAULT_THROTTLES</code> setting. For example.</p>
|
||||
<pre class="prettyprint lang-py"><code>API_SETTINGS = {
|
||||
'DEFAULT_THROTTLES': (
|
||||
'djangorestframework.throttles.AnonThrottle',
|
||||
'djangorestframework.throttles.UserThrottle',
|
||||
)
|
||||
'DEFAULT_THROTTLE_RATES': {
|
||||
'anon': '100/day',
|
||||
'user': '1000/day'
|
||||
}
|
||||
}
|
||||
</code></pre>
|
||||
<p>You can also set the throttling policy on a per-view basis, using the <code>APIView</code> class based views.</p>
|
||||
<pre class="prettyprint lang-py"><code>class ExampleView(APIView):
|
||||
throttle_classes = (UserThrottle,)
|
||||
|
||||
def get(self, request, format=None):
|
||||
content = {
|
||||
'status': 'request was permitted'
|
||||
}
|
||||
return Response(content)
|
||||
</code></pre>
|
||||
<p>Or, if you're using the <code>@api_view</code> decorator with function based views.</p>
|
||||
<pre class="prettyprint lang-py"><code>@api_view('GET')
|
||||
@throttle_classes(UserThrottle)
|
||||
def example_view(request, format=None):
|
||||
content = {
|
||||
'status': 'request was permitted'
|
||||
}
|
||||
return Response(content)
|
||||
</code></pre>
|
||||
<h2 id="anonthrottle">AnonThrottle</h2>
|
||||
<p>The <code>AnonThrottle</code> will only ever throttle unauthenticated users. The IP address of the incoming request is used to identify </p>
|
||||
<p><code>AnonThrottle</code> is suitable if you want to restrict the rate of requests from unknown sources.</p>
|
||||
<h2 id="userthrottle">UserThrottle</h2>
|
||||
<p><code>UserThrottle</code> is suitable if you want a simple restriction</p>
|
||||
<h2 id="scopedthrottle">ScopedThrottle</h2>
|
||||
<h2 id="custom-throttles">Custom throttles</h2>
|
||||
</div><!--/span-->
|
||||
</div><!--/row-->
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
134
css/default.css
Normal file
134
css/default.css
Normal file
|
@ -0,0 +1,134 @@
|
|||
/* Set the body padding-top when above 980px to push the content down from
|
||||
below the navbar, which is fixed at >980px screen widths. */
|
||||
@media (min-width: 980px) {
|
||||
body {
|
||||
padding-top: 71px;
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
|
||||
pre {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.dropdown .dropdown-menu {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.dropdown.open .dropdown-menu {
|
||||
display: block;
|
||||
}
|
||||
|
||||
/* Header link to GitHub */
|
||||
.repo-link {
|
||||
float: right;
|
||||
margin-right: 10px;
|
||||
margin-top: 9px;
|
||||
}
|
||||
|
||||
/* GitHub 'Star' badge */
|
||||
body.index #main-content iframe {
|
||||
float: right;
|
||||
margin-top: -12px;
|
||||
margin-right: -15px;
|
||||
}
|
||||
|
||||
/* Travis CI badge */
|
||||
body.index #main-content p:first-of-type {
|
||||
float: right;
|
||||
margin-right: 8px;
|
||||
margin-top: -14px;
|
||||
margin-bottom: 0px;
|
||||
}
|
||||
|
||||
/* Github source file badges */
|
||||
a.github {
|
||||
float: right;
|
||||
margin-top: -12px;
|
||||
margin-right: 12px;
|
||||
}
|
||||
|
||||
a.github:hover {
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
/* Force TOC text to not overrun */
|
||||
#table-of-contents {
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
/* Code blocks should scroll horizontally */
|
||||
pre {
|
||||
overflow: auto;
|
||||
word-wrap: normal;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
/* Preserve the spacing of the navbar across different screen sizes. */
|
||||
.navbar-inner {
|
||||
padding: 5px 0;
|
||||
}
|
||||
|
||||
@media (max-width: 979px) {
|
||||
.navbar .brand {
|
||||
margin-left: 0;
|
||||
padding-left: 0;
|
||||
}
|
||||
.navbar-inner .container-fluid {
|
||||
padding-left: 15px;
|
||||
}
|
||||
}
|
||||
|
||||
.nav-list li.main {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
/* Set the table of contents to static so it flows back into the content when
|
||||
viewed on tablets and smaller. */
|
||||
@media (max-width: 767px) {
|
||||
#table-of-contents {
|
||||
position: static;
|
||||
}
|
||||
}
|
||||
|
||||
/* When the page is in two-column layout, give the main content some room
|
||||
to breath on the left. */
|
||||
@media (min-width: 768px) {
|
||||
#main-content {
|
||||
padding-left: 1em;
|
||||
}
|
||||
}
|
||||
|
||||
/* Cutesy quote styling */
|
||||
blockquote {
|
||||
font-family: Georgia, serif;
|
||||
font-size: 18px;
|
||||
font-style: italic;
|
||||
margin: 0.25em 0;
|
||||
padding: 0.25em 40px;
|
||||
line-height: 1.45;
|
||||
position: relative;
|
||||
color: #383838;
|
||||
border-left: none;
|
||||
}
|
||||
|
||||
blockquote:before {
|
||||
display: block;
|
||||
content: "\201C";
|
||||
font-size: 80px;
|
||||
position: absolute;
|
||||
left: -10px;
|
||||
top: -20px;
|
||||
color: #7a7a7a;
|
||||
}
|
||||
|
||||
blockquote p:last-child {
|
||||
color: #999999;
|
||||
font-size: 14px;
|
||||
display: block;
|
||||
margin-top: 5px;
|
||||
}
|
||||
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
<link href="http://tomchristie.github.com/django-rest-framework/css/prettify.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/bootstrap-responsive.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/drf-styles.css" rel="stylesheet">
|
||||
<link href="http://tomchristie.github.com/django-rest-framework/css/default.css" rel="stylesheet">
|
||||
|
||||
<!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
|
||||
<!--[if lt IE 9]>
|
||||
|
|
Loading…
Reference in New Issue
Block a user