Django:在生产环境中部署静态文件 [英] Django: Deploying static files in production environment
问题描述
我已经在生产环境中部署了django应用程序.应用程序的功能还可以,但是未渲染静态文件(css和图像).
I've deployed my django application in production environment. Application's functionality is OK but the static files (css and image) were not rendered.
在运行collectstatic之前,我已经在settings.py中设置了以下内容:
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',
)
在我的应用程序目录(即E:/django/project/app/)下,我已经创建了static和staticfiles目录,并放置了该应用程序使用的css和图像(尽管我不确定这是否是必要,因为我认为这是完全多余的,因为这是由Collectstatic完成的.
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).
我遵循了 django的部署说明.但是,我再次担心的是CSS和图像未渲染.我应该做什么/修改来解决这个问题?
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!
推荐答案
设置DEBUG = False将导致在开发环境中加载静态文件时出现问题.始终在开发环境中设置DEBUG = True.
Setting DEBUG=False will cause u problem in loading static files in development environment. Always set DEBUG=True in development environment.
这篇关于Django:在生产环境中部署静态文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!