A middleware for Django applications using Cloudflare as a proxy. Allows you to extract and access CF headers.
Project description
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+
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_cloudflare-1.0.0.tar.gz.
File metadata
- Download URL: django_cloudflare-1.0.0.tar.gz
- Upload date:
- Size: 64.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6d60184cf7c6486dd15d9cf87f0cf8ec790428e2a2ba0f84fcd7d28baf5132b
|
|
| MD5 |
966eab26df776b45023898b226c935fa
|
|
| BLAKE2b-256 |
c1150ce3e90ca7992287f191436c335c1d11c915254ce1101c935857e09d943e
|
Provenance
The following attestation bundles were made for django_cloudflare-1.0.0.tar.gz:
Publisher:
release.yml on tomwojcik/django-cloudflare
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_cloudflare-1.0.0.tar.gz -
Subject digest:
f6d60184cf7c6486dd15d9cf87f0cf8ec790428e2a2ba0f84fcd7d28baf5132b - Sigstore transparency entry: 970404571
- Sigstore integration time:
-
Permalink:
tomwojcik/django-cloudflare@647b619ff5a1710dbf298778d79cfdef79bf8ced -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/tomwojcik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@647b619ff5a1710dbf298778d79cfdef79bf8ced -
Trigger Event:
release
-
Statement type:
File details
Details for the file django_cloudflare-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_cloudflare-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cd522747217e65ec9e45966d846fdf63703edc0a2ec2e9165f8d664bd7a356f6
|
|
| MD5 |
adbde77450631262e89d83784c7f8796
|
|
| BLAKE2b-256 |
fd77858298c2592037257cbb13e346237209e82bdf3daab2c7e014a64d08420c
|
Provenance
The following attestation bundles were made for django_cloudflare-1.0.0-py3-none-any.whl:
Publisher:
release.yml on tomwojcik/django-cloudflare
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
django_cloudflare-1.0.0-py3-none-any.whl -
Subject digest:
cd522747217e65ec9e45966d846fdf63703edc0a2ec2e9165f8d664bd7a356f6 - Sigstore transparency entry: 970404575
- Sigstore integration time:
-
Permalink:
tomwojcik/django-cloudflare@647b619ff5a1710dbf298778d79cfdef79bf8ced -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/tomwojcik
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@647b619ff5a1710dbf298778d79cfdef79bf8ced -
Trigger Event:
release
-
Statement type: