4

저는 장고 압축 작업을하려고하지만 내 {% static %} 사용으로 인해 작동하지 않는다고 생각합니다.Django를 {% static %}로 압축하십시오.

내 템플릿 (내가 pyjade를 사용하고 있지만 중요하지 않습니다)입니다

:

- load staticfiles 
- load compress 

| {% compress css %} 
link(rel="stylesheet", href="{% static 'less/bootstrap.css' %} ") 
link(rel="stylesheet", href="{% static 'timepicker/css/bootstrap-timepicker.min.css'%}") 
link(rel="stylesheet", href="{% static 'leaflet/addons/locatecontrol/L.Control.Locate.css' %} ") 
link(rel="stylesheet", href="http://cdn.leafletjs.com/leaflet-0.6.4/leaflet.css") 
link(href='//api.tiles.mapbox.com/mapbox.js/v1.3.1/mapbox.css', rel='stylesheet') 
| {% endcompress %} 

그리고 내 settings.py의 일부 :

PROJECT_DIR = os.path.dirname(os.path.realpath(__file__)) 

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

STATICFILES_DIRS = (
    os.path.join(PROJECT_DIR, 'media'), 
) 

STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder', 
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
    #'django.contrib.staticfiles.finders.DefaultStorageFinder', 
    'compressor.finders.CompressorFinder', 
) 

COMPRESS_URL = STATIC_URL 
COMPRESS_ROOT = STATIC_ROOT 
COMPRESS_STORAGE = "staticfiles.storage.StaticFileStorage" 

INSTALLED_APPS = (....,'compressor',....) 

을 나는 압축하지 않는 $ python manage.py collectstatic하더라도 작업하고 원본 파일을 뱉어냅니다. docs it says에서 나는 내가 준 생각한 절대 경로를 제공해야합니까? 누군가 압축 작업을 할 수 있습니까? 감사. (나는 장고의 정적 파일에 익숙하지 않다.)


업데이트

내가 설정에서 COMPRESS_ENABLED = True (및 DEBUG=False)를 활성화 티미의 의견을 따른 후, 여전히 파일을 찾을 필요가있다 :

UncompressableFileError at/
'less/bootstrap.css ' could not be found in the COMPRESS_ROOT '/Users/diolor/mysite/wsgi/static' or with staticfiles. 

그냥주의하는 것이 그 정적 파일 올바르게 발견되어 렌더링됩니다 (COMPRESS_ENABLED = False).

내 구조 :

mysite/ 
    wsgi/ 
     myapp/ 
     settings.py 
     manage.py 
     media/ 
      #js & css files 
     static/ 
     [...] 

압축은 CSS와 {% static %}에 문제가 것 같습니다 시간 재생이 끝난 후. link(rel="stylesheet", href="{% static 'less/bootstrap.css' %} ") 그것이 오류가 발생합니다 당신이 link(rel="stylesheet", href="/static/less/bootstrap.css") 그것 greaty이있는 경우

는 스타일 시트를 압축합니다. JS에

, 그것은 잘 그것을 렌더링 : script(type="text/javascript", src='{% static "bootstrap/js/bootstrap.min.js" %}')

+2

Compressor는'DEBUG = False' 또는 특히'COMPRESS = True'로 설정되었을 때만 작동합니다. –

+0

@ TimmyO'Mahony 감사합니다. 당신 말이 맞습니다. 업데이트를 확인해 주시겠습니까? – Diolor

답변

8

문제는 당신이 %}" 사이 HREF의 끝 부분에 공간을 가지고있다. 오류 메시지를주의 깊게 보면 컴프레서가 끝에 공백이있는 파일을 찾고 있음을 알 수 있습니다. (리플릿 스타일 시트와 동일합니다.)

+0

당신은 나의 하루 친구를 구했습니다! –

+0

당신이 저를 구해 줬습니다, 감사합니다. –