New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Serving Static Files #61
Comments
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. |
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 Any chances to FIX that? Passing custom storage instance via |
Here is an example of a patch marcinn@61557b4 EDIT: sorry, it seems that output from 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. 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. |
I can't find any way to thumbnail a static (in STATIC_ROOT) file. It only seems to work on external (http://....) and media (in MEDIA_ROOT) files.
This is very helpful when the output size of a static image is not always the same (be it through user preferences, theming, etc)
The text was updated successfully, but these errors were encountered: