Python Django:您在使用staticfiles应用程序时未设置STATIC_ROOT设置 [英] Python Django: You're using the staticfiles app without having set the STATIC_ROOT setting

查看:167
本文介绍了Python Django:您在使用staticfiles应用程序时未设置STATIC_ROOT设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Django应用程序部署到Web上,但是出现以下错误:

I'm trying to deploy my Django application to the web, but I get the following error:


您正在使用staticfiles应用程序,而未将STATIC_ROOT
设置设置为文件系统路径

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

但是,我在制作中做了。 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'


推荐答案

production.py 文件是什么?如何导入设置?

What is the production.py file? How do you import your settings?

根据出现此错误的方式(通过wsgi服务器或命令行提供django服务),检查 manage.py wsgi.py 查看默认设置文件的名称。

Depending on how you got this error (serving django through a wsgi server or on the command line), check for manage.py or wsgi.py to see what is the name of the default settings file.

如果要手动设置要使用的设置,请使用以下命令:

If you want to manuallly set the settings to use, use something like this:

./manage.py --settings=production

production 在哪里

此外,您的设置文件不应导入任何与django相关的内容。如果您想将设置拆分为不同的环境,请使用类似的内容。

Moreover, your settings file should not import anything django related. If you want to split your settings for different environments, use something like this.

文件 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.py settings / production.py 之类的文件…

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

这篇关于Python Django:您在使用staticfiles应用程序时未设置STATIC_ROOT设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆