简体   繁体   English

django.core.exceptions.ImproperlyConfigured:您使用的是静态文件应用程序,而没有将 STATIC_ROOT 设置设置为文件系统路径

[英]django.core.exceptions.ImproperlyConfigured: You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path

在此处输入图像描述 静态文件 when i run git push heroku master it says that my STATIC_ROOT is improperly configured (ERROR:raise ImproperlyConfigured("You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path".). I have set my STATIC_ROOT just as shown in a video tutuorial.当我运行 git push heroku master 时,它说我的 STATIC_ROOT 配置不正确(错误:raise ImproperlyConfigured(“您正在使用静态文件应用程序而没有将 STATIC_ROOT 设置设置为文件系统路径”。)。我已将我的 STATIC_ROOT 设置为在视频教程中显示。

settings.py设置.py

import django_heroku
import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '###############################'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = (os.environ.get('DEBUG_VALUE') == 'True')


ALLOWED_HOSTS = ['http://mypytalk.herokuapp.com/']

# Application definition

INSTALLED_APPS = [
    'blog.apps.BlogConfig',
    'users.apps.UsersConfig',
    'crispy_forms',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'storages'
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'pytalk.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'pytalk.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    }
}

# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]

# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATIC_URL = '/static/'


MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

CRISPY_TEMPLATE_PACK = 'bootstrap4'

LOGIN_REDIRECT_URL = 'blog-home'
LOGIN_URL = 'login'

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
EMAIL_HOST_USER = os.environ.get('EMAIL_USER')
EMAIL_HOST_PASSWORD = os.environ.get('EMAIL_PASS')

DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'

# Activate Django-Heroku.
django_heroku.settings(locals())

.gitignore .gitignore

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
<<<<<<< HEAD
=======
pip-wheel-metadata/
>>>>>>> 661353800061e4584535573f7e8b813cb01040c2
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
#  Usually these files are written by a python script from a template
#  before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
<<<<<<< HEAD
cover/
=======
>>>>>>> 661353800061e4584535573f7e8b813cb01040c2

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
<<<<<<< HEAD
.pybuilder/
=======
>>>>>>> 661353800061e4584535573f7e8b813cb01040c2
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
<<<<<<< HEAD
#   For a library or package, you might want to ignore these files since the code is
#   intended to run in multiple environments; otherwise, check them in:
# .python-version
=======
.python-version
>>>>>>> 661353800061e4584535573f7e8b813cb01040c2

# pipenv
#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
#   However, in case of collaboration, if having platform-specific dependencies or dependencies
#   having no cross-platform support, pipenv may install dependencies that don't work, or not
#   install all needed dependencies.
#Pipfile.lock

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/

# Celery stuff
celerybeat-schedule
celerybeat.pid

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/
<<<<<<< HEAD

# pytype static type analyzer
.pytype/

# Cython debug symbols
cython_debug/

/.idea/
.idea/workspace.xml
=======
>>>>>>> 661353800061e4584535573f7e8b813cb01040c2

You need to name these variables like this (and remember to create the corresponding folders):您需要像这样命名这些变量(并记住创建相应的文件夹):

STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATICFILES_DIRS = [os.path.join(BASE_DIR, 'staticfiles'), ]

As you added STATIC ROOT into your settings.py.当您将 STATIC ROOT 添加到您的 settings.py 中时。 You also have to add static directory path into root directory's urls.py file, where you have your settings.py file.您还必须将 static 目录路径添加到根目录的 urls.py 文件中,其中包含您的 settings.py 文件。

from django.views.static import serve

path('static/<path:path>/', serve, {'document_root': settings.STATIC_ROOT, }),

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 配置不当:您使用的是staticfiles应用,而未将STATIC_ROOT设置设置为文件系统路径 - ImproperlyConfigured:You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path 您正在使用 staticfiles 应用程序,而没有将 STATIC_ROOT 设置设置为文件系统路径 - You're using the staticfiles app without having set the STATIC_ROOT setting to a filesystem path Python Django:您使用的是静态文件应用程序,而没有将 STATIC_ROOT 设置设置为文件系统路径 - Python Django: You're using the staticfiles app without having set the STATIC_ROOT setting setting to a filesystem path Python Django:您正在使用 staticfiles 应用程序,而没有设置 STATIC_ROOT 设置 - Python Django: You're using the staticfiles app without having set the STATIC_ROOT setting django.core.exceptions.ImproperlyConfigured - django.core.exceptions.ImproperlyConfigured Django.core.exceptions.ImproperlyConfigured: - Django.core.exceptions.ImproperlyConfigured: django.core.exceptions.Improperly配置有关设置模板 - django.core.exceptions.ImproperlyConfigured about setting TEMPLATES Django-Oscar错误-django.core.exceptions.ImproperlyConfigured:应用程序标签不唯一,重复:staticfiles - Django-oscar error - django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: staticfiles django.core.exceptions.ImproperlyConfigured:请求设置 LOGGING_CONFIG - django.core.exceptions.ImproperlyConfigured: Requested setting LOGGING_CONFIG 使用 appengine “django.core.exceptions.ImproperlyConfigured:设置 SECRET_KEY 环境变量”在 Google 云上部署 Django 应用程序时出错 - Error in deploying Django app on Google cloud using appengine "django.core.exceptions.ImproperlyConfigured: Set the SECRET_KEY environment variable"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM