Skip to main content

DjangoCloudflareCDN

Overview

DjangoCloudflareCDN is a simple Python package that allows you to easily integrate Cloudflare R2 with Django for serving static and media files. It provides a seamless setup using django-storages and boto3 to configure Django’s storage backends for Cloudflare R2.

Features

  • Integrates Cloudflare R2 as the static and media file storage for Django.
  • Supports custom domain setup for Cloudflare R2.
  • Automatically configures django-storages for S3-compatible storage with Cloudflare R2.
  • Provides customizable settings for Cloudflare R2, including access keys and cache control.

Installation

pip install django-cloudflare-cdn

Usage

  1. Add DjangoCloudflareCDN to your INSTALLED_APPS in settings.py:
INSTALLED_APPS = [
    # other apps
    'DjangoCloudflareCDN',
]
  1. Import the Cloudflare R2 settings in your settings.py
# settings.py

from DjangoCloudflareCDN import cloudflare_r2
  1. Configure Cloudflare R2 credentials and settings
# settings.py

# Cloudflare R2 Settings
AWS_ACCESS_KEY_ID = '<your-access-key>'
AWS_SECRET_ACCESS_KEY = '<your-secret-key>'
AWS_STORAGE_BUCKET_NAME = '<your-bucket-name>'
AWS_S3_ENDPOINT_URL = 'https://<your-account-id>.r2.cloudflarestorage.com'
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400'
}

AWS_S3_CUSTOM_DOMAIN = f'{AWS_STORAGE_BUCKET_NAME}.r2.cloudflarestorage.com'

# Static File Settings
STATIC_URL = f'https://{AWS_S3_CUSTOM_DOMAIN}/'

# Use S3Boto3Storage as the default storage backend
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
  1. Run the collectstatic command to upload your static files to Cloudflare R2 (Depends on api configuration)
python manage.py collectstatic

Optional Settings

Custom ACL for Files: Uncomment the AWS_DEFAULT_ACL line to make all files publicly readable.

    #settins.py

    AWS_DEFAULT_ACL = 'public-read'

Cache Control: Customize the cache control settings for your files.

    AWS_S3_OBJECT_PARAMETERS = {
        'CacheControl': 'max-age=86400'
    }

Troubleshooting

  • Ensure that your Cloudflare R2 bucket is properly configured.

  • Double-check your Cloudflare R2 credentials (Access Key and Secret Key).

  • If files are not showing up, ensure that you have run the collectstatic command.

Metadata

Release files for django-cloudflare-cdn 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-cdn 1.0.0
File Size Uploaded Provenance Actions
django_cloudflare_cdn-1.0.0.tar.gz 3.7 kB Without provenance Details for django_cloudflare_cdn-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-cloudflare-cdn 1.0.0
File Interpreter ABI Platform Actions
django_cloudflare_cdn-1.0.0-py3-none-any.whl Python 3 none any Details for django_cloudflare_cdn-1.0.0-py3-none-any.whl

Total release size: 7.8 kB

Release files / django_cloudflare_cdn-1.0.0.tar.gz

Download URL django_cloudflare_cdn-1.0.0.tar.gz
Size 3.7 kB
Tags Source
SHA-256 checksum
How to use checksums
9656160cf576fb9b65f862fe99da2f4a8604ba4fb2fb085974bfa9530c58b2a1
BLAKE2b-256 checksum
How to use checksums
4fa50a3b113fb29c68b067eba6249f7e34cd7ae65181546bf0564960926264dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / django_cloudflare_cdn-1.0.0-py3-none-any.whl

Download URL django_cloudflare_cdn-1.0.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
22e24628e559ad9cdbf59c48dbf6732ddfde6e3ed058ca729722635483104137
BLAKE2b-256 checksum
How to use checksums
5b223ec8fddcd31224d14c646beb0a2629e1e18a010ef244dccdb14c64fb43b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for django-cloudflare-cdn 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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

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.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No 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