Comments (13)
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.
Out of curiosity, did you add 'compressor.finders.CompressorFinder'
to your STATICFILES_FINDERS
setting as shown in the installation docs?
from django-compressor.
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.
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.
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.
I've pushed several fixes to the develop branch, I'd be happy if you could try those out.
from django-compressor.
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.
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.
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.
@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.
Lemme me know if that suffices :)
from django-compressor.
Much more readable, thanks!
from django-compressor.
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)
- Django's `get_storage_class` is deprecated in 4.2 (Django 5.1 compat.) HOT 5
- Releasing a new version with Django 4.2 support HOT 3
- No way to specify hashing method for JS files? HOT 1
- Disable offline compression for some scripts HOT 5
- Fix tests with Python 3.9.17, 3.10.12 and 3.11.4 HOT 7
- Dependencies are pinned HOT 1
- Dynamic SCRIPT_NAME and compressed assets HOT 8
- Getting more info when `Error parsing template` happens
- Not compatible with django-components HOT 10
- Issue with losing templates in compress command in version >=3.0.
- optional max_workers for compress command HOT 1
- 'Settings' object has no attribute 'COMPRESSORS' HOT 8
- OSSFuzz Integration HOT 4
- 4.4: compressor.exceptions.OfflineGenerationError raised in tests HOT 4
- Django 5.1 compatibility HOT 1
- Offline compression + inlining bug HOT 3
- Compress command: warn or error about context vars?
- Set compressor_file_storage to CompressorFileStorage HOT 13
- Documentation isn't clear / confusing behavior
- Getting an "invalid template" error for template in a library that I do not use HOT 3
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 django-compressor.