Adding throttling options
Note
It is advised to go through point 2 of Marking models to create REST APIs and Adding Custom Serializer and have an understanding of passing custom view attributes.
Here, an example of ScopedRateThrottle class is given as other types of classes and options can be managed solely via settings.py
.
Let us consider the below model:
models.py | |
---|---|
To add throttling class, the dictionary returned by getParams()
method of a ViewParams
class must have an entry with key constants.THROTTLE_SCOPE
. For example:
view_params.py | |
---|---|
Now, let us go back to models.py and see how to provide the throttle scope as viewset attribute.
models.py | |
---|---|
Also, ensure that throttle class and other options are specified in settings.py
: