Comments (3)
Here is an example of a patch marcinn@61557b4
EDIT: sorry, it seems that output from thumbnail.url
is valid, but when retrieved from cached.url
it is prefixed with /media/
instead of /static/
. There is somethin' more broken inside.
EDIT (2): there is a design issue in deserializing storage code - the storage class is loaded and instantiated with defaults instead of using existing instance. In the other words - sorl.thumbnail does not reuse storage instance but creates own (configured differently). As a workaround we can inherit from FileSystemStorage and define custom initializer.
After applying it anyone can easily generate thumbnails for anything.
It is possible to create a custom template tag like this one:
from django.core.files.storage import FileSystemStorage
from django.conf import settings
from django import template
from sorl.thumbnail.templatetags.thumbnail import ThumbnailNode
register = template.Library()
class StaticThumbnailStorage(FileSystemStorage):
def __init__(self, *args, **kw):
super(StaticThumbnailStorage, self).__init__(
*args, location='/path/to/custom/static/'
base_url=settings.STATIC_URL, **kw)
storage = StaticThumbnaikStorage()
class StaticThumbnailNode(ThumbnailNode):
def _get_thumbnail(self, file_, geometry, **options):
options['storage'] = storage
return super(StaticThumbnailNode, self)._get_thumbnail(
file_, geometry, **options)
@register.tag
def static_thumbnail(parser, token):
return StaticThumbnailNode(parser, token)
Please note that settings do not need to be changed.
from sorl-thumbnail.
You need to use some storage that uses STATIC_ROOT, for example you can use 'django.core.files.storage.FileSystemStorage' and instantiate with location=settings.STATIC_ROOT and base_url=settings.STATIC_URL, please continue on stackoverflow as this is not a bug.
from sorl-thumbnail.
After five years still there is no possibility to generate thumbs from static files without changing the DEFAULT storage, because of https://github.com/mariocesar/sorl-thumbnail/blob/master/sorl/thumbnail/base.py#L100
StackOverflow will not help due to implementation.
Any chances to FIX that? Passing custom storage instance via get_thumbnail()
will be enough.
from sorl-thumbnail.
Related Issues (20)
- Automatic tests are not run with Django 4.0 & 4.1 HOT 1
- link on sorl-thumbnail/AUTHORS should be clickable
- Setting storage class does not support deconstructors
- Django 4.1 template tag 'thumbnail' conflict with easy-thumbnails HOT 1
- "Schematic view of how things are done" link in the documentation is dead HOT 1
- Support Django 4.2 - settings.DEFAULT_FILE_STORAGE is deprecated HOT 5
- Should an empty thumbnail template tag raise an exception?
- Delete old thumbnails from the media/cache directory and the database HOT 5
- image doesn't upload at resize_image field given path.
- DeprecationWarning from setuptools 67.5.0 and above HOT 9
- Make THUMBNAIL_STORAGE contain a storage key
- Release new version to support Django 4.2 HOT 14
- Master tests fail HOT 2
- Cache using FileSystemStorage storage engine and not the S3Boto3Storage one defined HOT 1
- Review and accept or reject pending pull requests HOT 2
- AWS S3 with sorl-thumbnail is super slow HOT 9
- How to create a thumbnail in a view, rather than dynamically via a template?
- Broken link in the docs
- django 4.2 - storage options (problem with s3 and template tag)
- Broken links in cache after clear_delete_all
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sorl-thumbnail.