Django: Deploying static files in production envir

2019-09-01 15:10发布

问题:

I've deployed my django application in production environment. Application's functionality is OK but the static files (css and image) were not rendered.

I've set the following in my settings.py, prior running collectstatic:

DEBUG = False
TEMPLATE_DEBUG = False

STATICFILES_STORAGE = 'django.contrib.staticfiles.storage.StaticFilesStorage'
STATIC_ROOT = 'E:/django/project/app/static/'
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    'E:/django/project/app/staticfiles/',
)

TEMPLATE_CONTEXT_PROCESSORS = (
    'django.core.context_processors.static',
)

TEMPLATE_DIRS = (
    'E:/django/project/app/templates',
)

INSTALLED_APPS = (
   'django.contrib.staticfiles',
   'project.app',
)

Under my app directory (i.e. E:/django/project/app/), I've created both static and staticfiles directories, and placed the css and the image used by the app (though I am not sure if this is necessary because I think this is quite redundant for this is done by the collectstatic).

I followed django's deployment instruction here. But again, my concern is the CSS and the image are not rendered. What should I do/modify to address this?

Your ideas are greatly appreciated. Thanks in advance!

回答1:

Setting DEBUG=False will cause u problem in loading static files in development environment. Always set DEBUG=True in development environment.