django-cors-headers

Configurable CORS headers middleware for Django applications

Library
PyPI
v4.9.0
5,585stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
70/100Good
Development Activity76
Maintenance32
Community72
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
79/100Good
Architecture78
Code Quality90
Innovation62
Learning Curve85

django-cors-headers is a Django application that adds Cross-Origin Resource Sharing (CORS) headers to HTTP responses, allowing in-browser requests to reach your Django backend from other origins. It ships as a single middleware class plus a small settings surface (allow-lists, regex origin matching, credential support, private-network access) so teams can expose an API to a separate frontend domain, a mobile app, or third-party integrations without hand-rolling header logic.

Originally created in 2013 and now maintained by Adam Johnson with contributions from 70+ people, it has become the de facto standard for CORS in the Django ecosystem, used by hundreds of thousands of projects that separate their API from their frontend (React/Vue SPAs, mobile clients, partner integrations).

What You Get

  • A single CorsMiddleware class supporting both sync and async Django request/response cycles
  • Exact-match (CORS_ALLOWED_ORIGINS) and regex-match (CORS_ALLOWED_ORIGIN_REGEXES) origin allow-lists
  • A Django signal (check_request_enabled) for fully custom, per-request CORS logic (e.g. DB-backed multi-tenant origin lists)
  • Support for credentials, exposed headers, custom allowed headers/methods, preflight cache duration, and Private Network Access preflight handling
  • Built-in Django system checks that catch misconfigured settings (wrong types, malformed origins) at startup rather than at request time

Common Use Cases

  • Serving a Django REST/GraphQL API to a separately-hosted single-page app (React, Vue, Svelte) during local development and in production
  • Allowing a mobile app or third-party partner service to call a Django-backed API from a browser-based origin
  • Multi-tenant SaaS platforms that need to allow CORS from arbitrary customer subdomains via regex or a DB-driven signal handler
  • Locking down which origins, methods, and headers are permitted for security-sensitive internal APIs

Under The Hood

Architecture - The library is a single Django “app” (corsheaders) with a clean separation of concerns: middleware.py holds the one public entry point (CorsMiddleware), which reads all behavior from a lazily-evaluated conf.Settings object (conf.py) that shadows Django’s settings module with defaults from defaults.py. Preflight (OPTIONS) requests are short-circuited in check_preflight() before hitting the view, while normal responses get headers appended in add_response_headers() after the view runs — origin checks flow through exact allow-list, regex allow-list, and finally an opt-in Django Signal (check_request_enabled in signals.py) for fully custom logic, giving three escalating levels of configurability without ever touching the middleware’s code.

Tech Stack - Pure Python (100%) with a minimal dependency footprint: only asgiref>=3.6 (for iscoroutinefunction/markcoroutinefunction sync/async detection) and django>=5.2. Build tooling is modern and lightweight — setuptools build backend, ruff for linting (with isort, pyupgrade, flake8-bugbear rule sets enabled), mypy --strict for type-checking, and uv for dependency/test-matrix management across Django 5.2/6.0/6.1 and Python 3.10-3.14.

Code Quality - The tests/ directory (749 lines across 6 files) exercises the middleware extensively in test_middleware.py (467 lines covering allow-list matching, regex matching, signals, credentials, preflight, and private-network headers) plus a dedicated test_checks.py (159 lines) that validates every Django system-check error path (corsheaders.E001-E015). The project advertises 100% coverage via CI badge, uses mypy --strict with warn_unreachable and redundant-expr enabled, and every public function carries type hints — a strong quality bar with no unaddressed technical debt visible in the source.

API Design - The public surface is deliberately tiny: add one middleware class to MIDDLEWARE, add corsheaders to INSTALLED_APPS, and set 1-2 settings (CORS_ALLOWED_ORIGINS or CORS_ALLOW_ALL_ORIGINS). Settings names are self-documenting and mirror Django’s own naming conventions, with backwards-compatible aliases retained for renamed settings (e.g. CORS_ORIGIN_WHITELIST still works as an alias for CORS_ALLOWED_ORIGINS). The README documents every setting with defaults and examples, and startup-time system checks fail fast with actionable error messages when a setting is misconfigured, minimizing the debugging loop for new users.

Used by 10 apps in this directory

Python
68%
Other

Baserow

No Code Platforms · Databases

5,635

Open-source no-code platform to build databases, apps, automations, and AI agents — self-hosted or cloud, with full data ownership.

View details
89
Repo Health
84
Technical
68
Dependency
Built with
Python68%
JavaScript15%
Vue12%
Updated today
Python
51%
MIT

Docs

File Storage · CMS

16,733

Open-source collaborative knowledge platform with real-time editing, AI writing tools, and full self-hosting control — built by the French and German governments.

View details
87
Repo Health
81
Technical
72
Dependency
Built with
Python51%
TypeScript42%
Updated 2 days ago
Python
64%
BSD 3

Flagsmith

Developer Tools · Devops · Ab Testing Experimentation

6,518

Open-source feature flagging, remote config, and A/B/multivariate testing platform for web, mobile, and server-side apps — self-host or use the hosted SaaS.

View details
91
Repo Health
82
Technical
65
Dependency
Built with
Python64%
TypeScript31%
Updated today
HTML
48%
LGPL-2.1

Horilla

Human Resources · ERP

1,330

Open-source HRMS covering recruitment, attendance, payroll, and biometrics in one self-hosted Django application.

View details
88
Repo Health
60
Technical
65
Dependency
Built with
HTML48%
Python35%
JavaScript13%
Updated today
TypeScript
38%
Apache 2.0

Label Studio

AI Development · Data Engineering

28,083

Label Studio is an open-source, multi-type data labeling platform that lets teams annotate images, text, audio, video, and time series data with a configurable XML-based UI and export annotations in formats ready for any ML framework.

View details
93
Repo Health
87
Technical
68
Dependency
Built with
TypeScript38%
JavaScript27%
Python25%
Updated today
Python
60%
MIT

LibrePhotos

File Storage

8,044

Self-hosted photo library with AI-powered face recognition, semantic search, and automatic event albums — no cloud required.

View details
82
Repo Health
78
Technical
67
Dependency
Built with
Python60%
TypeScript37%
Updated 3 days ago
Python
61%
GPL 3.0

Paperless-ngx

Bookmarks Archiving

44,394

Turn your paper pile into a searchable digital archive with OCR, AI classification, and automated workflows — all running on your own server.

View details
91
Repo Health
88
Technical
70
Dependency
Built with
Python61%
TypeScript30%
Updated today
TypeScript
55%
Other

Phase Console

Security · Devops

904

End-to-end encrypted secrets management for engineering teams — from local dev to Kubernetes production.

View details
84
Repo Health
73
Technical
67
Dependency
Built with
TypeScript55%
Python44%
Updated today
Python
55%
Other

PostHog

Analytics · Monitoring · Developer Tools

37,777

The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.

View details
92
Repo Health
80
Technical
67
Dependency
Built with
Python55%
TypeScript36%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search