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"
Development
Installing for development:
make install
Cleaning the installation:
make clean
Format the code:
make format
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
Hashes for django-cloudflare-images-0.5.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e8e19d15469c9e71cee6967c810b4cf04406d54298fe312a20ea5d1475c88ca |
|
MD5 | d33c9797374c8ad2f9fb1e63cce6f1ec |
|
BLAKE2b-256 | 7ccbbd0c5d65b1dbc92cf75db0be721447cb909f574081aefca88292c80ca898 |
Hashes for django_cloudflare_images-0.5.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abe952d4fbbb2ccd7b44af6ce81a07539fc8e043228a2161230e817ef71d89bf |
|
MD5 | 35c808bf8cf3008c99b967aa8ab60ee6 |
|
BLAKE2b-256 | 7377a0f30a32ecf2394b07ffa2fefb06533c5f171b0d05c805a60185aabbec7f |