2017-09-09 46 views
0

我正在使用cookiecutter django模板開發一個項目:https://github.com/pydanny/cookiecutter-django 該項目在docker容器中運行,該容器隨ubuntu 16.04LTS上的cookiecutter-django模板提供。找不到Django靜態文件數值錯誤

當試圖讓現場製作,它會返回在一些網頁上出現以下錯誤:

the file 'events\css\themes\fontawesome-stars.css' could not be found with <whitenoise.storage.CompressedManifestStaticFilesStorage object at 0x7f830be38ac8>. 

文件夾結構是:在碼頭工人的構建過程和後報告

./project/events/static/ 
└── events 
    ├── css 
       ├── details.css 
       ├── list.css 
       └── themes 
        ├── fontawesome-stars.css 
        └── fontawesome-stars-o.css 

沒有錯誤運行collectstatic。服務器上的文件 權限設置爲775

在base.py配置靜態配置:

# STATIC FILE CONFIGURATION 
# ------------------------------------------------------------------------------ 
# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-root 
STATIC_ROOT = str(ROOT_DIR('staticfiles')) 

# See: https://docs.djangoproject.com/en/dev/ref/settings/#static-url 
STATIC_URL = '/static/' 

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#std:setting-STATICFILES_DIRS 
STATICFILES_DIRS = [ 
    str(APPS_DIR.path('static')), 
] 

# See: https://docs.djangoproject.com/en/dev/ref/contrib/staticfiles/#staticfiles-finders 
STATICFILES_FINDERS = [ 
    'django.contrib.staticfiles.finders.FileSystemFinder', 
    'django.contrib.staticfiles.finders.AppDirectoriesFinder', 
] 

在模板我包括像這樣:

{% load static %} 
{% load crispy_forms_tags %} 
{% block title %} 
{% endblock%} 

{% block css %} 
{{block.super}} 
<link rel="stylesheet" type="text/css" href="http://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css"> 
<link rel="stylesheet" type="text/css" href="{% static 'events\css\themes\fontawesome-stars.css' %}"> 
{% endblock %} 

回答

1
文件

你如何在模板中包含靜態文件?看起來你是直接指定路徑。相反,你應該使用:

{% load staticfiles %} 
<link rel="stylesheet" type="text/css" href="{% static 'events/css/themes/fontawesome-stars.css' %}"> 

由於生產whitenoisecollectstatic命令將增加額外的內容的文件名版本,緩存和其他用途。

+0

我已經包含了與你建議應該完成的相同的方式。 將靜態更改爲靜態文件不會改變任何內容。 – MarkerDave

+1

@Niikhawod在剛剛添加的示例中,您使用的是「\」而不是「/」。這可能是問題所在。 – dethos

+0

太棒了,如果那是問題所在。我的答案應該是正確的。 – dethos