Skip to main content

Build Status Python Versions Latest Version Docs

django-cloudflare

A reusable Django middleware that allows you to easily extract Cloudflare headers from incoming requests.

Resources:

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)

Source distribution for django-cloudflare 1.0.0
File Size Uploaded Provenance
django_cloudflare-1.0.0.tar.gz 64.2 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for django-cloudflare 1.0.0
File Interpreter ABI Platform
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 log

Release 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 log

Security 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.

Select from 2 files

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 log

A 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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page