Cloudflare Images integration for Django
Project description
django-cloudflare-images
This is a Django library to add support to Cloudflare Images to the ImageField.
It supports:
- Django 3
- Django 4
- Django 5
Installation
pip install django-cloudflare-images
Setup
You need to add the following your settings.py:
- If you are running Django 4.2+:
STORAGES = {"default": {"BACKEND": "cloudflare_images.storage.CloudflareImagesStorage"}}
- Else:
DEFAULT_FILE_STORAGE = "cloudflare_images.storage.CloudflareImagesStorage"
And then add the remaining of the configuration:
CLOUDFLARE_IMAGES_ACCOUNT_ID = "XXX"
CLOUDFLARE_IMAGES_API_TOKEN = "YYY"
CLOUDFLARE_IMAGES_ACCOUNT_HASH = "ZZZ"
If you wish to use a default variant for a specific field you need to change your ImageField
to a CloudflareImagesField
see example below:
from cloudflare_images.field import CloudflareImagesField
from django.db import models
class MyModel(models.Model):
image = CloudflareImagesField(variant="custom")
Please note that you will need to migrate your model(s) once you swapped the field(s). No SQL will actually be applied (you can check by running sqlmigrate <module> <number>
).
If you wish to use a custom domain to serve your images you need to add the following to your settings.py:
CLOUDFLARE_IMAGES_DOMAIN = "example.com"
If you wish to use a default variant other than "public" to serve your images you need to add the following to your settings.py:
CLOUDFLARE_IMAGES_VARIANT = "custom"
If you wish to override the default timeout of 60 seconds for API requests, you need to add the following to your settings.py:
CLOUDFLARE_IMAGES_API_TIMEOUT = 120
Development
Installing for development:
make install
Cleaning the installation:
make clean
Format the code:
make format
Check the code (for linting errors):
make check
Running all tests:
make test
Create a sdist+bdist package in dist/:
make package
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
File details
Details for the file django_cloudflare_images-0.6.0.tar.gz
.
File metadata
- Download URL: django_cloudflare_images-0.6.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bbabb87860a72e0387e8ddb8d71365bf5401997f1b0b8eaad71420fa80ca745b |
|
MD5 | 835b5570fd0597d078fa29c702dd3932 |
|
BLAKE2b-256 | f8f65eac43997c2eb797071efb29658df49053be0a873fc23a30033038fd3f7b |
File details
Details for the file django_cloudflare_images-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: django_cloudflare_images-0.6.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.1.dev0+g94f810c.d20240510 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd7ae17a29784b7f570f8a82cf64fc6ce6539e0193baafdd5532885dc319d18e |
|
MD5 | 31169feaeda6320c102e5a08c1e3f3c7 |
|
BLAKE2b-256 | d608f00887096f4867290eb16b9f21232f9a624beeb6a94fa16550187905613d |