Skip to content

Commit 6a6b2c9

Browse files
committed
2 parents 5c4bf53 + e98c229 commit 6a6b2c9

File tree

9 files changed

+26
-16
lines changed

9 files changed

+26
-16
lines changed

docs/api-guide/throttling.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ As with permissions, multiple throttles may be used. Your API might have a rest
1212

1313
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 to some services being particularly resource-intensive.
1414

15-
Multiple throttles can also be used if you want to impose both burst throttling rates, and sustained throttling rates. For example, you might want to limit a user to a maximum of 60 requests per minute, and 1000 requests per day.
15+
Multiple throttles can also be used if you want to impose both burst throttling rates, and sustained throttling rates. For example, you might want to limit a user to a maximum of 60 requests per minute, and 1000 requests per day.
1616

1717
Throttles do not necessarily only refer to rate-limiting requests. For example a storage service might also need to throttle against bandwidth, and a paid data service might want to throttle against a certain number of a records being accessed.
1818

@@ -44,7 +44,7 @@ You can also set the throttling policy on a per-view or per-viewset basis,
4444
using the `APIView` class based views.
4545

4646
class ExampleView(APIView):
47-
throttle_classes = (UserThrottle,)
47+
throttle_classes = (UserRateThrottle,)
4848

4949
def get(self, request, format=None):
5050
content = {
@@ -55,7 +55,7 @@ using the `APIView` class based views.
5555
Or, if you're using the `@api_view` decorator with function based views.
5656

5757
@api_view('GET')
58-
@throttle_classes(UserThrottle)
58+
@throttle_classes(UserRateThrottle)
5959
def example_view(request, format=None):
6060
content = {
6161
'status': 'request was permitted'
@@ -72,22 +72,22 @@ The throttle classes provided by REST framework use Django's cache backend. You
7272

7373
## AnonRateThrottle
7474

75-
The `AnonThrottle` will only ever throttle unauthenticated users. The IP address of the incoming request is used to generate a unique key to throttle against.
75+
The `AnonRateThrottle` will only ever throttle unauthenticated users. The IP address of the incoming request is used to generate a unique key to throttle against.
7676

7777
The allowed request rate is determined from one of the following (in order of preference).
7878

79-
* The `rate` property on the class, which may be provided by overriding `AnonThrottle` and setting the property.
79+
* The `rate` property on the class, which may be provided by overriding `AnonRateThrottle` and setting the property.
8080
* The `DEFAULT_THROTTLE_RATES['anon']` setting.
8181

82-
`AnonThrottle` is suitable if you want to restrict the rate of requests from unknown sources.
82+
`AnonRateThrottle` is suitable if you want to restrict the rate of requests from unknown sources.
8383

8484
## UserRateThrottle
8585

86-
The `UserThrottle` will throttle users to a given rate of requests across the API. The user id is used to generate a unique key to throttle against. Unauthenticated requests will fall back to using the IP address of the incoming request to generate a unique key to throttle against.
86+
The `UserRateThrottle` will throttle users to a given rate of requests across the API. The user id is used to generate a unique key to throttle against. Unauthenticated requests will fall back to using the IP address of the incoming request to generate a unique key to throttle against.
8787

8888
The allowed request rate is determined from one of the following (in order of preference).
8989

90-
* The `rate` property on the class, which may be provided by overriding `UserThrottle` and setting the property.
90+
* The `rate` property on the class, which may be provided by overriding `UserRateThrottle` and setting the property.
9191
* The `DEFAULT_THROTTLE_RATES['user']` setting.
9292

9393
An API may have multiple `UserRateThrottles` in place at the same time. To do so, override `UserRateThrottle` and set a unique "scope" for each class.
@@ -113,11 +113,11 @@ For example, multiple user throttle rates could be implemented by using the foll
113113
}
114114
}
115115

116-
`UserThrottle` is suitable if you want simple global rate restrictions per-user.
116+
`UserRateThrottle` is suitable if you want simple global rate restrictions per-user.
117117

118118
## ScopedRateThrottle
119119

120-
The `ScopedThrottle` class can be used to restrict access to specific parts of the API. This throttle will only be applied if the view that is being accessed includes a `.throttle_scope` property. The unique throttle key will then be formed by concatenating the "scope" of the request with the unique user id or IP address.
120+
The `ScopedRateThrottle` class can be used to restrict access to specific parts of the API. This throttle will only be applied if the view that is being accessed includes a `.throttle_scope` property. The unique throttle key will then be formed by concatenating the "scope" of the request with the unique user id or IP address.
121121

122122
The allowed request rate is determined by the `DEFAULT_THROTTLE_RATES` setting using a key from the request "scope".
123123

docs/api-guide/viewsets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ For example:
9898

9999
from django.contrib.auth.models import User
100100
from rest_framework import viewsets
101+
from rest_framework import status
101102
from rest_framework.decorators import action
102103
from rest_framework.response import Response
103104
from myapp.serializers import UserSerializer, PasswordSerializer

docs/topics/ajax-csrf-cors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ To guard against these type of attacks, you need to do two things:
2323

2424
If you're using `SessionAuthentication` you'll need to include valid CSRF tokens for any `POST`, `PUT`, `PATCH` or `DELETE` operations.
2525

26-
The Django documentation describes how to [include CSRF tokens in AJAX requests][csrf-ajax].
26+
In order to make AJAX requests, you need to include CSRF token in the HTTP header, as [described in the Django documentation][csrf-ajax].
2727

2828
## CORS
2929

docs/topics/browsable-api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ All of the blocks available in the browsable API base template that can be used
7575
* `branding` - Branding section of the navbar, see [Bootstrap components][bcomponentsnav].
7676
* `breadcrumbs` - Links showing resource nesting, allowing the user to go back up the resources. It's recommended to preserve these, but they can be overridden using the breadcrumbs block.
7777
* `footer` - Any copyright notices or similar footer materials can go here (by default right-aligned).
78+
* `script` - JavaScript files for the page.
7879
* `style` - CSS stylesheets for the page.
7980
* `title` - Title of the page.
8081
* `userlinks` - This is a list of links on the right of the header, by default containing login/logout links. To add links instead of replace, use `{{ block.super }}` to preserve the authentication links.
@@ -170,4 +171,4 @@ You can now add the `autocomplete_light.ChoiceWidget` widget to the serializer f
170171
[autocomplete-packages]: https://www.djangopackages.com/grids/g/auto-complete/
171172
[django-autocomplete-light]: https://github.com/yourlabs/django-autocomplete-light
172173
[django-autocomplete-light-install]: http://django-autocomplete-light.readthedocs.org/en/latest/#install
173-
[autocomplete-image]: ../img/autocomplete.png
174+
[autocomplete-image]: ../img/autocomplete.png

docs/topics/credits.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@ The following people have helped make REST framework great.
147147
* Rudolf Olah - [omouse]
148148
* Gertjan Oude Lohuis - [gertjanol]
149149
* Matthias Jacob - [cyroxx]
150+
* Pavel Zinovkin - [pzinovkin]
151+
* Will Kahn-Greene - [willkg]
152+
* Kevin Brown - [kevin-brown]
153+
* Rodrigo Martell - [coderigo]
150154

151155
Many thanks to everyone who's contributed to the project.
152156

@@ -330,3 +334,7 @@ You can also contact [@_tomchristie][twitter] directly on twitter.
330334
[omouse]: https://github.com/omouse
331335
[gertjanol]: https://github.com/gertjanol
332336
[cyroxx]: https://github.com/cyroxx
337+
[pzinovkin]: https://github.com/pzinovkin
338+
[coderigo]: https://github.com/coderigo
339+
[willkg]: https://github.com/willkg
340+
[kevin-brown]: https://github.com/kevin-brown

docs/tutorial/5-relationships-and-hyperlinked-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ We can easily re-write our existing serializers to use hyperlinking.
8080
highlight = serializers.HyperlinkedIdentityField(view_name='snippet-highlight', format='html')
8181

8282
class Meta:
83-
model = models.Snippet
83+
model = Snippet
8484
fields = ('url', 'highlight', 'owner',
8585
'title', 'code', 'linenos', 'language', 'style')
8686

rest_framework/fields.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ class EmailField(CharField):
512512
form_field_class = forms.EmailField
513513

514514
default_error_messages = {
515-
'invalid': _('Enter a valid e-mail address.'),
515+
'invalid': _('Enter a valid email address.'),
516516
}
517517
default_validators = [validators.validate_email]
518518

rest_framework/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def get_default_fields(self):
690690
assert field_name in ret, \
691691
"Noexistant field '%s' specified in `read_only_fields` " \
692692
"on serializer '%s'." % \
693-
(self.__class__.__name__, field_name)
693+
(field_name, self.__class__.__name__)
694694
ret[field_name].read_only = True
695695

696696
return ret

rest_framework/tests/test_serializer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ def test_wrong_data(self):
494494
}
495495
serializer = self.CommentSerializerWithFieldValidator(data=wrong_data)
496496
self.assertFalse(serializer.is_valid())
497-
self.assertEqual(serializer.errors, {'email': ['Enter a valid e-mail address.']})
497+
self.assertEqual(serializer.errors, {'email': ['Enter a valid email address.']})
498498

499499

500500
class PositiveIntegerAsChoiceTests(TestCase):

0 commit comments

Comments
 (0)