In this example, the @ratelimit
decorator is applied to the my_view
function-based view. The key
argument specifies whether to rate limit based on the user or IP address. The rate
argument defines the rate limit, where '60/m'
means a maximum of 60 requests per minute. The block
argument determines whether to block further requests when the limit is exceeded.
Step 4: Customizing Rate Limiting Response By default, the django-ratelimit
package returns a 429 Too Many Requests response when the rate limit is exceeded. However, you can customize the response by defining a handler in your Django project’s urls.py
file: