I'm trying to compile SASS and compress CSS files with django pipeline on Django 1.6.3, but I get the following error after visiting my site:
ValueError: The file 'css/test2.css' could not be found with <pipeline.storage.PipelineCachedStorage object at 0x0585DF50>.
I configured pipeline following the guide on readthedocs.org: I added pipeline to INSTALLED_APPS
then I defined STATIC_URL
and STATIC_ROOT
:
STATIC_URL = '/test/forum/skins/default/media/'
STATIC_ROOT = '/test/forum/skins/default/media/'
Folders tree:
I added SASSCompiler
to PIPELINE_COMPILERS
and then I added the path to the file to be compressed:
# pipeline settings
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_COMPILERS = (
'pipeline.compilers.sass.SASSCompiler',
)
PIPELINE_CSS = {
'main': {
'source_filenames': (
'css/test.scss',
),
'output_filename': 'css/test2.css',
},
}
Finally I linked the css to my XHTML index:
{% load compressed %}
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
{% compressed_css 'main' %}
</head>
I do not understand what I did wrong. Thanks for any help!
When I run collectstatic
this copy the files from django and not from my project
F:\DEV\DJANGO\apps\test>python manage.py collectstatic
You have requested to collect static files at the destination
location as specified in your settings:
F:\test\forum\skins\default\media
This will overwrite existing files!
Are you sure you want to do this?
Type 'yes' to continue, or 'no' to cancel: yes
Copying 'F:\DEV\DJANGO\apps\django\django\contrib\admin\static\admin\css\base.
css'
Copying 'F:\DEV\DJANGO\apps\django\django\contrib\admin\static\admin\css\chang
elists.css'
Copying 'F:\DEV\DJANGO\apps\django\django\contrib\admin\static\admin\css\dashb
oard.css'
Copying 'F:\DEV\DJANGO\apps\django\django\contrib\admin\static\admin\css\forms
.css'
Copying 'F:\DEV\DJANGO\apps\django\django\contrib\admin\static\admin\css\ie.cs
s'
[etc .... ]
But the path F:\test\forum\skins\default\media
is wrong, my project is located
in F:\DEV\DJANGO\apps\test\forum\skins\default\media
.
Then I tried to find the static file:
F:\DEV\DJANGO\apps\test> python manage.py findstatic css/main.css
No matching file found for 'css/main.css'.
But the file exists.
In Django's settings.py
, the STATIC_ROOT
variable tells Django where to move your static files, whereas STATIC_URL
is the URL path that users will see and from where you can access the files within the browser. See the Django documentation on static files:
https://docs.djangoproject.com/en/dev/ref/settings/#static-files
For example, lets's say you have the following in your settings.py file:
STATIC_ROOT = "/var/www/example.com/static/"
STATIC_URL = "/static/"
Now, let's you are doing your software development on the same machine within /home/fuiba/git/your-django-project/
. Within your Django project you have a sub-directory called static, and within that directory you have a file called custom.css
. The full path to this file is:
`/home/fuiba/git/your-django-project/static/custom.css`
Now, after running python manage.py collectstatic
your style sheet is moved to your STATIC_ROOT
directory. Now you start the web server and you can access the static file via the project's STATIC_URL
. So, let's assume you run the web server on the localhost on port 8000, you can access the stylesheet from your browser at the following location:
http://localhost:8000/static/custom.css
Ok, that's the foundation for how it works. In your case, you appear to be developing under Windows, so there's a few caveats. First, don't use backslashes ('\') in your paths, use only forward slashes. However, you still must specify the drive letter and colon. So, let's set your STATIC_ROOT
to:
STATIC_ROOT = "F:/DEV/DJANGO/apps/test-static-root/"
I'm choosing this so you don't pollute your test project directory, and a sibling directory should be created in the above location with your static files within.
Let me know how you get along, and I'll try to provide more details.
Good luck!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With