2012-04-18 77 views
3

我剛剛安裝Django管道到我的Django應用程序,它似乎並沒有壓縮我的JavaScript文件。它似乎正確安裝,因爲模板標籤正常工作。我正在使用manage.py collectstatic來壓縮文件。這是我目前的配置。我還設置了我的應用程序,以使用Django 1.3中的每個django-pipeline文檔使用django-staticfiles。Django管道不壓縮

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'site_media', 'static') 
STATIC_URL = '/site_media/static/' 
ADMIN_MEDIA_PREFIX = '/site_media/static/admin/' 

STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, "media"), 
) 

STATICFILES_FINDERS = (
    ##Turn these on if using django.contrib.staticfiles 
    ##'django.contrib.staticfiles.finders.FileSystemFinder', 
    ##'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
    ##'django.contrib.staticfiles.finders.DefaultStorageFinder', 

    ##Turn these on if using django.contrib.staticfiles 
    'staticfiles.finders.FileSystemFinder', 
    'staticfiles.finders.AppDirectoriesFinder', 
    'staticfiles.finders.DefaultStorageFinder' 
) 

PREREQ_APPS = [ 
    # Django 
    'django.contrib.admin', 
    'django.contrib.auth', 
    'django.contrib.contenttypes', 
    'django.contrib.sessions', 
    'django.contrib.sites', 

    #External 
    'south', 
    'staticfiles', 
    'pipeline',  
] 


PIPELINE_YUI_BINARY='/Applications/yuicompressor-2.4.7/build/yuicompress' 

PIPELINE_JS = { 
    'site': { 
     'source_filenames': (
      'js/libs/ddsmoothmenu.js', 
      'js/script.js', 
     ), 
     'output_filename': 'js/script.min.js', 
    } 
} 

我不確定我在這裏錯過了什麼,但我確定它是某種東西。我沒有收到任何錯誤消息或任何東西,它只是不壓縮。

感謝您的幫助!

+0

現在不應該使用'django.contrib.staticfiles',因爲它包含在標準的Django發行版中? – Cerin 2013-05-15 19:33:31

+0

@Cerin你是對的,我剛剛解決了這個問題。我不再使用django-staticfiles,而是使用contrib。 – ralph 2013-05-17 23:29:24

回答

1

難道你設置staticfiles:

STATICFILES_STORAGE = 'pipeline.storage.PipelineCachedStorage' 

如果是:

  • 你的JS文件最終是空的?

  • '/Applications/yuicompressor-2.4.7/build/yuicompress'可執行腳本?

+0

這似乎是問題所在。我沒有正確設置STATICFILES_STORAGE。我假設默認是好的。謝謝你的幫助! – ralph 2012-04-18 14:17:52

1

你在你的設置中有DEBUG=True嗎?嘗試添加PIPELINE=True,以確保它運行壓縮

+0

我已經嘗試了這兩個,但仍然沒有運氣。當我打開PIPELINE標誌和DEBUG標誌時,它會查找壓縮文件,但實際上並沒有對其進行壓縮。 – ralph 2012-04-18 11:36:08

+0

聽起來這可能是一個權限問題。你在開發中還是在生產服務器上? – 2012-04-18 11:37:45

+0

我在django開發服務器上運行。我已經檢查了YUI Compressor以確保所有的dir確保所有的權限設置正確。我的第一個猜測是,它沒有正確調用YUICompressor,但由於沒有錯誤消息,我不知道它在做什麼。 – ralph 2012-04-18 11:58:38