django-cloudflare
A reusable Django middleware that allows you to easily extract Cloudflare headers from incoming requests.
Resources:
- Source: https://github.com/tomwojcik/django-cloudflare
- Documentation: https://django-cloudflare.readthedocs.io/
- Changelog: https://django-cloudflare.readthedocs.io/en/latest/changelog/
Supported headers
| Cloudflare header | Default attribute | Setting to enable |
|---|---|---|
Cdn-Loop |
request.cf_cdn_loop |
CF_HEADER_CDN_LOOP_ENABLED |
Cf-Connecting-Ip |
request.cf_ip |
CF_HEADER_IP_ENABLED |
Cf-Connecting-Ipv6 |
request.cf_ipv6 |
CF_HEADER_IPV6_ENABLED |
Cf-Ipcountry |
request.cf_country |
CF_HEADER_COUNTRY_ENABLED |
Cf-Ray |
request.cf_ray |
CF_HEADER_RAY_ENABLED |
Cf-Visitor |
request.cf_visitor |
CF_HEADER_VISITOR_ENABLED |
Cf-Warp-Tag-Id |
request.cf_warp_tag |
CF_HEADER_WARP_TAG_ENABLED |
X-Forwarded-For |
request.cf_forwarded_for |
CF_HEADER_FORWARDED_FOR_ENABLED |
X-Forwarded-Proto |
request.cf_forwarded_proto |
CF_HEADER_FORWARDED_PROTO_ENABLED |
All headers are disabled by default. Each attribute name can be customized via the corresponding *_ATTR_NAME setting.
Installation
pip install -U django-cloudflare
Usage
Add the middleware and enable the headers you need in your settings.py:
MIDDLEWARE += ["django_cloudflare.CloudflareMiddleware"]
CF_HEADER_IP_ENABLED = True
CF_HEADER_COUNTRY_ENABLED = True
Then access the values on the request object:
def my_view(request):
ip = request.cf_ip
country = request.cf_country
Both sync and async views are supported.
Requirements
Python 3.10+, Django 4.2+
Metadata
Release files for django-cloudflare 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_cloudflare-1.0.0.tar.gz | 64.2 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_cloudflare-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 68.8 kB
Release files / django_cloudflare-1.0.0.tar.gz
| Download URL | django_cloudflare-1.0.0.tar.gz |
|---|---|
| Size | 64.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6d60184cf7c6486dd15d9cf87f0cf8ec790428e2a2ba0f84fcd7d28baf5132b
|
|
BLAKE2b-256 checksum How to use checksums |
c1150ce3e90ca7992287f191436c335c1d11c915254ce1101c935857e09d943e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.
Transparency logRelease files / django_cloudflare-1.0.0-py3-none-any.whl
| Download URL | django_cloudflare-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cd522747217e65ec9e45966d846fdf63703edc0a2ec2e9165f8d664bd7a356f6
|
|
BLAKE2b-256 checksum How to use checksums |
fd77858298c2592037257cbb13e346237209e82bdf3daab2c7e014a64d08420c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.
Transparency logSecurity for django-cloudflare 1.0.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for django_cloudflare-1.0.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 19, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.