在發展模式,我的Django應用程序從STATICFILES_DIRS的*一個服務靜態文件,而不是其他。的Django沒有看到所有STATIC_DIRS
這是我在settings.py文件代碼:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'bower_components'), # OK
os.path.join(BASE_DIR, 'practice_custom'), # Not OK
]
STATICFILES_FINDERS = [
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
]
文件中bower_components被發現,但文件practice_custom都沒有。兩個目錄都在同一個地方(頂層)。如果我重新命名bower_components目錄然後bower_componentszzzzzz的文件都沒有找到,這意味着它們正在通過staticfiles應用程序中。我們在find()方法(---尋找:)中將代碼中的打印語句放在代碼中,並且它顯示了提供的路徑,正如您可以看到的那樣格式相同,但一個結果爲404.
---looking for: practice_custom/xyz/style.css
[09/Mar/2017 21:55:11] "GET /static/practice_custom/xyz/style.css HTTP/1.1" 404 1732
---looking for: bower_components/c3/c3.min.css
[09/Mar/2017 21:55:11] "GET /static/bower_components/c3/c3.min.css HTTP/1.1" 200 2043
任何想法?
編輯:
在檢查FileSystemFinder.find_location()我看到了它在尋找bower_components/bower_components,然後在頂層的bower_components具有峯值目錄,發現它確實有一個子目錄名爲bower_components,這是工作的唯一原因!
雖然當我運行collectstatic
我得到靜態/ bower_components /引導等...因爲我希望看到。
/manage.py
/bower_components/bower_components/bootstrap
/static/bower_components/bootstrap
/...
所以我想,問題是爲什麼它這樣做?!
什麼是你的Django和Python版本? – rodorgas
Django是1.9.5,Python是3.5 – andyhasit