aboutsummaryrefslogtreecommitdiffstats
path: root/docs/api-guide/throttling.md
diff options
context:
space:
mode:
authorTom Christie2013-01-30 13:41:56 +0000
committerTom Christie2013-01-30 13:41:56 +0000
commitbe6df3ae3ce18bf4b55ae065ebd34198885e48df (patch)
tree3a96bb6a5075584add7e28c6d8d7f251ad785b4e /docs/api-guide/throttling.md
parent9a4d01d687d57601d37f9a930d37039cb9f6a6f2 (diff)
parent8021bb5d5089955b171173e60dcc0968e13d29ea (diff)
downloaddjango-rest-framework-be6df3ae3ce18bf4b55ae065ebd34198885e48df.tar.bz2
Merge branch 'master' into many-fields
Conflicts: rest_framework/relations.py
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