aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/throttling.md
diff options
context:
space:
mode:
authorMichael Elovskikh2013-01-28 16:26:16 +0600
committerMichael Elovskikh2013-01-28 16:26:16 +0600
commit499d6424aee5b71b8e6b2500bf14fa85321bfc26 (patch)
tree34f575fb078377208ded5251aea050668355d82a /docs/api-guide/throttling.md
parent180c94dc44a9cc5b882364a58b0b12a8ab430c22 (diff)
parent3bcd38b7d0ddaa2c051ad230cb0d749f9737fd82 (diff)
downloaddjango-rest-framework-499d6424aee5b71b8e6b2500bf14fa85321bfc26.tar.bz2
Merge branch 'upstream_master' into docs_patch_method
Conflicts: docs/api-guide/authentication.md
Diffstat (limited to 'docs/api-guide/throttling.md')
-rw-r--r--docs/api-guide/throttling.md10
1 files changed, 9 insertions, 1 deletions
diff --git a/docs/api-guide/throttling.md b/docs/api-guide/throttling.md
index b03bc9e0..923593bc 100644
--- a/docs/api-guide/throttling.md
+++ b/docs/api-guide/throttling.md
@@ -150,8 +150,16 @@ User requests to either `ContactListView` or `ContactDetailView` would be restri
# Custom throttles
-To create a custom throttle, override `BaseThrottle` and implement `.allow_request(request, view)`. The method should return `True` if the request should be allowed, and `False` otherwise.
+To create a custom throttle, override `BaseThrottle` and implement `.allow_request(self, request, view)`. The method should return `True` if the request should be allowed, and `False` otherwise.
Optionally you may also override the `.wait()` method. If implemented, `.wait()` should return a recommended number of seconds to wait before attempting the next request, or `None`. The `.wait()` method will only be called if `.allow_request()` has previously returned `False`.
+## Example
+
+The following is an example of a rate throttle, that will randomly throttle 1 in every 10 requests.
+
+ class RandomRateThrottle(throttles.BaseThrottle):
+ def allow_request(self, request, view):
+ return random.randint(1, 10) == 1
+
[permissions]: permissions.md