Skip to content
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

Configurable CSS Loader #31

Closed
wants to merge 1 commit into from
Closed

Configurable CSS Loader #31

wants to merge 1 commit into from

Conversation

jpnauta
Copy link
Contributor

@jpnauta jpnauta commented Dec 2, 2016

Fixes issue #29 and serves as an alternative to pull request #19.

This code has been causing several issues for people:

class InlineCssNode(template.Node):
            ...
            if settings.DEBUG:
                expanded_path = finders.find(path)
            else:
                expanded_path = staticfiles_storage.path(path)

As an alternative of this code, I propose this BaseCSSLoader class.

If you want to always load CSS via staticfinders, you simply add this to your settings:

INLINECSS_CSS_LOADER = 'django_inlinecss.css_loaders.StaticFinderCSSLoader'

If you want to load CSS by URL, you can even do something like this:

# myapp.css_loaders.py
import requests
class StaticUrlCSSLoader(BaseCSSLoader):
    def load(self, path):
        """
        Retrieve CSS contents by URL
        """
        url = staticfiles_storage.url(path)
        response = requests.get(url)
        response.raise_for_status()

        return response.content

# settings.py
INLINECSS_CSS_LOADER = 'myapp.css_loaders.StaticUrlCSSLoader'

@loicgasser
Copy link

@melinath I had the same issue. Seems like this pull request addresses these issues. Do you care to review it? I guess this is a bit old now.

@melinath melinath mentioned this pull request Oct 23, 2019
@melinath
Copy link
Contributor

@loicgasser thanks for the ping - it looks like this is a pretty straightforward change with clear benefits that's affecting a number of people! Unfortunately the fork is deleted so I've moved this patch to #46. I'll add a couple tweaks and hopefully we can get this merged and released shortly.

@loicgasser
Copy link

Great news! Thank you! Let me know when you make a new release.

@melinath
Copy link
Contributor

This was resolved by #46 and the fix is included in 0.3.0, which just went out! Thanks again!

@melinath melinath closed this Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Breaking locally on finders.find
4 participants