Django: Deploying static files in production environment

老子叫甜甜 提交于 2019-12-25 02:37:24

问题


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.



来源:https://stackoverflow.com/questions/25396009/django-deploying-static-files-in-production-environment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!