django-ratelimit

Enforce Redis-backed rate limits on Django views with django-ratelimit.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/carlos-ASG/tu-voz-en-ruta --skill django-ratelimit
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: django-ratelimit
Source: https://github.com/carlos-ASG/tu-voz-en-ruta/tree/main/skills/django-ratelimit
Command: npx skills add https://github.com/carlos-ASG/tu-voz-en-ruta --skill django-ratelimit

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Django rate limiting patterns using django-ratelimit with Redis backend to protect views from abuse and spam. Trigger: When implementing rate limiting, spam protection, or throttling in Django views.

Core Features & Use Cases

  • Redis-backed rate limiting for Django views
  • Decorator-based integration for both function-based and class-based views
  • Flexible keys (ip, user, user_or_ip, header, GET/POST params)
  • Block or track mode to tailor response handling
  • Suitable for spam protection, brute-force mitigation, and API protection

Quick Start

Install dependencies and enable in a Django project:

  • pip install django-ratelimit redis
  • Configure Redis URL in settings (REDIS_URL) and set up CACHES backend
  • Apply the ratelimit decorator to a view, e.g.: from django.http import HttpRequest, HttpResponse from django_ratelimit.decorators import ratelimit

@ratelimit(key='ip', rate='5/m', method='POST', block=False) def submit_view(request: HttpRequest) -> HttpResponse: if getattr(request, 'limited', False): return HttpResponse('Rate limit exceeded', status=429) return HttpResponse('OK')

Frequently Asked Questions about django-ratelimit

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add rate limiting to Django views using Redis?

You add rate limiting to Django views by applying the django-ratelimit decorator with a Redis backend configured in your CACHES settings, supporting both function-based and class-based views to block or track excessive requests.

What is the difference between block and track modes in Django rate limiting?

In Django rate limiting, block mode automatically rejects requests that exceed the limit, while track mode allows the request to process but sets a limited attribute on the request object so you can handle the response manually.

Can I use django-ratelimit to throttle login attempts and prevent brute-force attacks?

Yes, django-ratelimit can throttle login attempts to prevent brute-force attacks by applying a decorator with a configured rate to your login view, using keys like ip or user_or_ip to identify and restrict abusive traffic.

Does Django rate limiting with Redis require any specific dependencies?

Django rate limiting with Redis requires Django, the django-ratelimit package, and the redis library installed via pip, along with a Redis-backed cache configured in your Django settings using a REDIS_URL.

What flexible keys can I use for Django API endpoint protection against spam?

For Django API endpoint protection, you can use flexible rate limiting keys including ip, user, user_or_ip, specific headers, or GET and POST parameters to accurately identify and throttle spam or abusive traffic patterns.

Why am I getting a 429 status code after applying a rate limit decorator to my Django view?

A 429 status code occurs because the rate limit decorator set the request's limited attribute to True after detecting excessive requests, and your view logic explicitly returns an HTTP 429 response when this attribute is present.