Giter VIP home page Giter VIP logo

Comments (3)

marcinn avatar marcinn commented on June 2, 2024 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.

sorl avatar sorl commented on June 2, 2024 1

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.

marcinn avatar marcinn commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.