Django pipeline not loading assets

I followed this tutorial to create a sample project. File structure:

- 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 the Django-pipeline for asset management. I set up my project the same as the codes below, but it doesn't load assets as expected.

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;
}

      

Generated output for http://127.0.0.1/polls

-

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

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

      

He cannot load the file /static/styles1.css

in the browser. Even, I have tested ./manage.py collectstatic

without any success. Did I miss something?

Python-3.4 and Django-1.7

+3


source to share


2 answers


Django pipline is updated very often, so your tutorials are already out of date. But I still want to answer your question because I just spent a couple of hours fixing the same problem with a new pipeline and want to share my solution and hope it is helpful to someone.

Everything works for:

  • Django == 1.9.1
  • Django-conveyor == 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>

      

+2


source


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

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

      



Using:

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

      

-3


source







All Articles