3

I've followed this tutorial to make a sample project. The structure of the files is:

- mysite
    - mysite
         - __init__.py
         - settings.py
         - urls.py
         - wsgi.py
    - polls
         - migrations
         - templates
             - polls.html
         - static
             - script.js
             - style.css
         - admin.py
         - models.py
         - tests.py
         - urls.py
         - views.py
    - manage.py

Everything works well, but, the problem is using of Django-pipeline for managing the assets. I've configured my project as same as below codes, but it doesn't load assets properly.

settings.py

INSTALLED_APPS = (
    .
    .
    'django.contrib.staticfiles',
    'pipeline',
    'polls',
)

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')
PIPELINE_ENABLED = True
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'
PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.cssmin.CSSMinCompressor'
PIPELINE_CSSMIN_BINARY = 'cssmin'
PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.slimit.SlimItCompressor'

PIPELINE_CSS = {
    'pollsX': {
        'source_filenames': (
          'style.css',
        ),
        'output_filename': 'styles1.css',
        'variant': 'datauri',
    },
}
PIPELINE_JS = {
    'pollsX': {
        'source_filenames': (
          'script.js',
        ),
        'output_filename': 'scripts1.js',
    }
}

polls.html

{% load compressed %}
{% compressed_css 'pollsX' %}

<div class='red-me'>
    <h1> Hi! I'm a templ! </h1>
</div>

style.css

.red-me {
    color: red;
}

The generated output for http://127.0.0.1/polls is

<link href="/static/styles1.css" rel="stylesheet" type="text/css" />

<div class='red-me'>
    <h1> Hi! I'm a templ! </h1>
</div>

It can not load /static/styles1.css file in the browser. Even, I tested ./manage.py collectstatic without any success. Did I miss something?

Python-3.4 and Django-1.7

masoud
  • 55,379
  • 16
  • 141
  • 208

2 Answers2

2

Django pipline updates very frequently, so your particular tutorials are outdated already. But I want to answer on your question anyway, because I just spent couple hours in fixing the same issue with new pipeline, and want to share my solution and hope it will be helpful for someone.

Everything works for:

  • Django==1.9.1
  • django-pipeline==1.6.4

settings.py

INSTALLED_APPS = (
    .
    .
    'django.contrib.staticfiles',
    'pipeline',
    'polls',
)

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static_files')

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    'pipeline.finders.PipelineFinder',
)

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

PIPELINE = {
    'CSS_COMPRESSOR': 'pipeline.compressors.cssmin.CSSMinCompressor',
    'CSSMIN_BINARY': 'cssmin',
    'JS_COMPRESSOR': 'pipeline.compressors.slimit.SlimItCompressor',
    'STYLESHEETS': {
        'pollsX': {
            'source_filenames': (
                'style.css',
            ),
            'output_filename': 'css/styles1.css',
            'variant': 'datauri',
        },
    },
    'JAVASCRIPT': {
        'pollsX': {
            'source_filenames': (
                'script.js',
            ),
            'output_filename': 'js/scripts1.js',
        },
    }
}   

polls.html

{% load pipeline %}
{% stylesheet 'pollsX' %}
{% javascript 'pollsX' %}

<div class='red-me'>
    <h1> Hi! I'm a templ! </h1>
</div>
rfedorov
  • 689
  • 7
  • 11
-3

I think you misspelled your css file name. Instead of using:

<link href="/static/styles1.css" rel="stylesheet" type="text/css" />

Use:

<link href="/static/style.css" rel="stylesheet" type="text/css" />
Vinicius Silva
  • 57
  • 1
  • 2
  • 6
  • he does not need to specify his compressed file names, will be done automatically by {% load pipeline %} and {% javascript 'homejs' %} when PIPELINE_ENABLED = True – 89n3ur0n Jun 14 '15 at 12:10
  • I was referring to a potential typo. Unrelated to compression file names. – Vinicius Silva Mar 01 '17 at 01:05