2

私は Django 1.8.2 を実行しており、django-pipeline 1.5.1を使用して CSS および JS ファイルを収集および圧縮しています。

を実行するpython manage.py collectstaticと、Django はすべてのファイルを収集し、設定どおりに圧縮します。しかし、Web サーバーにアクセスしたい場合、開発サーバーはすべての静的ファイルを提供しません。つまり、django-pipelineのものはロードできません。

私のテンプレートは次のようになります。

{% load pipeline %}
...
{% javascript 'master' %}

ページが開発サーバーに読み込まれると、Django はコードを次のように変換します。

<script charset="utf-8" src="/static/compressed/master.js" type="text/javascript"></script>

<link href="/static/img/favicon.ico" rel="icon"></link>

これまでのところかなり良いです。ただし、パイプラインからのファイルは提供できません。

"GET /static/compressed/master.js HTTP/1.1" 404 1774

master.jsしかし、静的フォルダーで失敗していることがわかります。

static
├── compressed
│   └── master.js
│   └── ...
└── img
    └── favicon.ico

ファビコンは提供されるのに、圧縮ファイルは提供されないのはなぜですか? 公式のチュートリアルに従い、再確認しました。助けてくれてありがとう。

追加 サイトは正常に機能し、静的ファイルは通常提供されます。この問題は、django-pipeline の圧縮ファイルでのみ発生します。

関連する設定

DEBUG = True

# Application definition

INSTALLED_APPS = (
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    # 3rd party
    'pipeline',
    'filer',
    'mptt',
    'easy_thumbnails',
    'tinymce',

    # Own apps
    'polls',
    'pages',
    'login',
    'archive',
)   

MIDDLEWARE_CLASSES = (
    'pipeline.middleware.MinifyHTMLMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

[...]

STATIC_URL = '/static/'

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

# Define Paths for Pipeline
STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage'

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

STATICFILES_DIRS = (
    os.path.join(BASE_DIR, 'templates/dpb'),
)

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

### Pipeline ###

# Set Pipeline Compilers
PIPELINE_COMPILERS = (
  'pipeline.compilers.sass.SASSCompiler',
)

PIPELINE_CSS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'

PIPELINE_JS_COMPRESSOR = 'pipeline.compressors.yuglify.YuglifyCompressor'

PIPELINE_ENABLED = True

PIPELINE_CSS = {
  'master': {
    'source_filenames': (
      'css/*.sass',
    ),
    'output_filename': 'compressed/master.css',
    'extra_context': {
      'media': 'screen, projection',
    },
  },
  'vendor': {
    'source_filenames': (
      'assets/bootstrap/css/bootstrap.min.css',
      'assets/bootstrap/css/bootstrap-theme.min.css',
      'assets/bootswatch/bootswatch.min.css',
    ),
    'output_filename': 'compressed/vendor.css'
  }
}

PIPELINE_JS = {
  'master': {
    'source_filenames': (
      'js/*.js',
    ),
    'output_filename': 'compressed/master.js'
  },
  'vendor': {
    'source_filenames': (
      'assets/jquery/jquery.min.js',
      'assets/bootstrap/js/bootstrap.min.js',
    ),
    'output_filename': 'compressed/vendor.js'
  }
}

### END Pipeline ###

[...]

urls.py

urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) + static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
4

1 に答える 1