Code Monkey home page Code Monkey logo

Comments (13)

jaap3 avatar jaap3 commented on July 30, 2024

I'm confused by this as well. Just upgraded a project from Django 1.2 to Django 1.3, previously using the non-contrib version of staticfiles, now using the django.contrib version.

I'm fairly certain I configured everything correctly but django_compressor tries to find files in STATIC_ROOT. During development I never run collectstatic so there are no files in STATIC_ROOT.

Reading the docs I see no clear way to make django_compressor work without first running collectstatic,

from django-compressor.

jezdez avatar jezdez commented on July 30, 2024

Out of curiosity, did you add 'compressor.finders.CompressorFinder' to your STATICFILES_FINDERS setting as shown in the installation docs?

from django-compressor.

jezdez avatar jezdez commented on July 30, 2024

With regard to the title, I can't reproduce it. Setting COMPRESS to False causes the compress tag to not consider performing the compression. Can you explain what result you get instead?

from django-compressor.

jaap3 avatar jaap3 commented on July 30, 2024

Definitely added 'compressor.finders.CompressorFinder' to the settings, as otherwise a beautiful (and helpful) exception will be raised.

As far as I understand the value of COMPRESS is the opposite of DEBUG. I did not explicitly set COMPRESS (or COMPRESSOR_COMPRESS) as the auto-configure logic seems sound. DEBUG is True, as I'm in development mode.

I've created a test project, using a startproject and tweaked the necessary settings.

Rendering an extremly simple template:

{% load compress %}
{% compress css %}
<link rel="stylesheet" href="{{ STATIC_URL }}foo.css">
{% endcompress %}

throws

Caught UncompressableFileError while rendering: '/path/to/project/static_media/static/foo.css' does not exist

from django-compressor.

jaap3 avatar jaap3 commented on July 30, 2024

btw, I'm using the version released today (0.6)

The actual location of foo.css would be '/path/to/project/static/foo.css', this path is also added to STATICFILES_DIRS

/path/to/project/static_media/static/ is the value of STATIC_ROOT, which is empty during development.

from django-compressor.

jezdez avatar jezdez commented on July 30, 2024

I've pushed several fixes to the develop branch, I'd be happy if you could try those out.

from django-compressor.

pagles avatar pagles commented on July 30, 2024

Yeap same here. The get_filename method in the Compress class gets the filename with

filename = os.path.join(settings.COMPRESS_ROOT, basename)

which is set to the STATIC_ROOT value.

To have it working it is required that static media are collected first.

from django-compressor.

jaap3 avatar jaap3 commented on July 30, 2024

Your changes fix this specific issue, but adds another one.

If I create a compress block with an external JS file:

{% compress js %}
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
{% endcompress %}

Nothing happens, according to the docs an exception should be raised:

If DEBUG is True, off-site files will throw exceptions. If DEBUG is False they will be silently stripped.

I'm pretty sure this issue (about off-site files not raising exceptions) was also present in previous versions of django-compressor.

Do you want me to file a new ticket about this?

On a different note: The render method of CompressorNode is very convoluted. You really need to do some refactoring to clear things up, all the comments you've added aren't really helping.

from django-compressor.

jaap3 avatar jaap3 commented on July 30, 2024

pagles mentions that get_filename is very naive about looking up files.

If django.contrib.staticfiles is installed you might want to make use of django.contrib.staticfiles.finders to get the actual location of a static file. Something like this should work:

from django.contrib.staticfiles import finders
filename = finders.find(basename, all=False) # returns the first match for a static file

Of course, if you want to stay compatible with previous versions of Django (and staticfiles), you'd want to create some compatibility layer around staticfiles (kinda like django.utils.hashcompat) and staticfiles detection.

I did some looking around in the source and there already is some duplicate code that handles staticfiles detection.

Both compressor.finders as compressor.settings check settings.INSTALLED_APPS for versions of staticfiles. Also in compressor.finders BaseStorageFinder is imported from staticfiles.finders. In previous versions of staticfiles (< 1.0) finders is called resolvers.

Anyway, this is way beyond the point of this issue... Probably also material for a new ticket.

from django-compressor.

jezdez avatar jezdez commented on July 30, 2024

@jaap3 Thank your for your suggestions, as always there is any reason to refactor the code. Don't hesitate to send pull requests with what you have in mind.

from django-compressor.

jezdez avatar jezdez commented on July 30, 2024

Lemme me know if that suffices :)

from django-compressor.

jaap3 avatar jaap3 commented on July 30, 2024

Much more readable, thanks!

from django-compressor.

rizumu avatar rizumu commented on July 30, 2024

Thanks, this version update helps. One thing that could have been clearer during my first 1.3 upgrade in the staticfiles docs that if you add CompressorFinder only, you are overriding the defaults, which is most likely unintended. I suggest including the defaults in the install instructions.

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # other finders..
    'compressor.finders.CompressorFinder',
)

from django-compressor.

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.