2016-04-21 26 views
6

我想我的部署Django應用到網上,但我得到了以下錯誤:Python的Django的:你正在使用的應用程序staticfiles而不必設置STATIC_ROOT設置

You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path

然而,我在我production.py

from django.conf import settings 

DEBUG = False 
TEMPLATE_DEBUG = True 
DATABASES = settings.DATABASES 

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

# Update database configuration with $DATABASE_URL. 
import dj_database_url 
db_from_env = dj_database_url.config(conn_max_age=500) 
DATABASES['default'].update(db_from_env) 

# Static files (CSS, JavaScript, Images) 
# https://docs.djangoproject.com/en/1.9/howto/static-files/ 

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) 

STATIC_URL = '/static/' 

# Extra places for collectstatic to find static files. 
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT, 'static'), 
) 

# Simplified static file serving. 
# https://warehouse.python.org/project/whitenoise/ 

STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage' 

回答

8

production.py文件是什麼?你如何導入你的設置?

根據您如何得到此錯誤(通過wsgi服務器或命令行提供django),請檢查manage.pywsgi.py以查看默認設置文件的名稱。

如果你想manuallly設置的設置使用,使用這樣的事情:

./manage.py --settings=production 

production任何Python模塊。

此外,你的設置文件不應該導入任何與django相關的東西。如果你想爲不同的環境分割你的設置,請使用類似的東西。

的文件settings/base.py

# All settings common to all environments 
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__)) 
STATIC_URL = '/static/' 
STATIC_ROOT = os.path.join(PROJECT_ROOT, 'static') 

文件,如settings/local.pysettings/production.py ...

# Production settings 
from settings.base import * 
DEBUG = False 
DATABASES = … 
0

設置STATIC_ROOT設置爲從您希望爲這些文件,例如目錄:

STATIC_ROOT =「/var/www/example.com/static/」

您正在使用的設置用於開發。查看Django文檔以獲取更多信息here

相關問題