Asynchronous thumbnail generation for sorl-thumbnail using Celery
Project description
Django Sorl Async Thumbnails
Asynchronous thumbnail generation for sorl-thumbnail using Celery.
Installation
pip install django-sorl-async-thumbnails
Configuration
- Add
sorl_async_thumbnailstoINSTALLED_APPS:
INSTALLED_APPS = [
...
'sorl.thumbnail',
'sorl_async_thumbnails',
...
]
-
Configure Celery in your project.
-
Add settings to
settings.py:
# Default settings
THUMBNAIL_BACKEND = 'sorl_async_thumbnails.backend.AsyncThumbnailBackend' #Set AsyncThumbnailBackend as backend for sorl.thumbnails
ASYNC_THUMBNAILS_BY_DEFAULT = False # Generate thumbnails asynchronously by default
ASYNC_THUMBNAILS_PLACEHOLDER = True # Use placeholder during generation
ASYNC_THUMBNAILS_PLACEHOLDER_STATICFILE = 'placeholder.jpg' # Path to placeholder image
ASYNC_THUMBNAILS_GENERATE_PLACEHOLDER_THUMB = True # Generate thumbnail for placeholder
ASYNC_THUMBNAILS_STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage' # Storage for placeholder
Usage
To generate thumbnails in synchronous mode regardless of settings, use the create_async=False keyword
Example
# In your model
from sorl.thumbnail import get_thumbnail
class MyModel(models.Model):
image = models.ImageField(upload_to='images/')
def get_thumbnail(self):
backend = AsyncThumbnailBackend()
# If ASYNC_THUMBNAILS_BY_DEFAULT is True, this will generate thumbnail asynchronously
return get_thumbnail(self.image, '100x100')
def get_thumbnail_sync(self):
backend = AsyncThumbnailBackend()
# Force synchronous generation
return get_thumbnail(self.image, '100x100', create_async=False)
def get_thumbnail_async(self):
backend = AsyncThumbnailBackend()
# Force asynchronous generation
return get_thumbnail(self.image, '100x100', create_async=True)
License
MIT
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_sorl_async_thumbnails-0.1.0.tar.gz.
File metadata
- Download URL: django_sorl_async_thumbnails-0.1.0.tar.gz
- Upload date:
- Size: 4.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9984a5e09e8d8261646712fe81b0ea8b43baea66642c5e087dd581e0005a6d5d
|
|
| MD5 |
9a85f5c748054a480825882c895954b3
|
|
| BLAKE2b-256 |
3c31677c0c6cf40f1751386d194f8aa4e936756640f81042ffede5ebf493eeaf
|
File details
Details for the file django_sorl_async_thumbnails-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_sorl_async_thumbnails-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
afc1b2508540669778ec56c18cfdccf4f872080cb3367d35eeae8da6384ba23b
|
|
| MD5 |
45ec94e0fdfed741a4879c4c444122b6
|
|
| BLAKE2b-256 |
7bc0ce99614fe9baf86672ee8ce989853b874b325b7a80c61f7e65007d4d7c28
|