Python 关于heroku调试设置的Django

Python 关于heroku调试设置的Django,python,django,heroku,Python,Django,Heroku,我对django的设置有点困惑 我在本地的settings.py文件中有类似的设置: """ Django settings for ebportfolio project. Generated by 'django-admin startproject' using Django 3.1.6. For more information on this file, see https://docs.djangoproject.com/en/3.1/topics/

我对django的设置有点困惑

我在本地的settings.py文件中有类似的设置:

"""
Django settings for ebportfolio project.

Generated by 'django-admin startproject' using Django 3.1.6.

For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

import environ

env = environ.Env(
    # set casting, default value
    DEBUG=(bool, False)
)
environ.Env.read_env()
DEBUG = env('DEBUG')

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = environ.Path(__file__)-1
# BASE_DIR = Path(__file__).resolve().parent.parent

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env('SECRET_KEY')
# SECURITY WARNING: don't run with debug turned on in production!

ALLOWED_HOSTS = ['127.0.0.1', 'my heroku address']

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'cloudinary',
    'cloudinary_storage',
    'django_summernote',
    'projects',
    'blog',
]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'whitenoise.middleware.WhiteNoiseMiddleware',
    '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 = 'ebportfolio.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': ['ebportfolio/templates'],
        '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 = 'ebportfolio.wsgi.application'

# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {
    # read os.environ['DATABASE_URL'] and raises ImproperlyConfigured exception if not found
    'default': env.db(),
    # read os.environ['SQLITE_URL']
}

# Password validation
# https://docs.djangoproject.com/en/3.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/3.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'Europe/London'

USE_I18N = True

USE_L10N = True

USE_TZ = True

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

public_root = BASE_DIR.path('')
MEDIA_ROOT = public_root('media')
MEDIA_URL = env.str('MEDIA_URL', default='media/')
STATIC_ROOT = public_root('staticfiles')
STATIC_URL = env.str('STATIC_URL', default='staticfiles/')

X_FRAME_OPTIONS = 'SAMEORIGIN'
# Configure Django App for Heroku.
DJANGO_SETTINGS_MODULE ='ebportfolio.settings'
import django_heroku

django_heroku.settings(locals())
当my.env文件DEBUG=True中的DEBUG=on时,图像将同时在线和本地显示。当我在.env中关闭DEBUG=off时,图像不会显示为在本地运行。有人能给我解释一下原因吗?调试是否影响文件的显示位置


在写文章时编辑-我在允许的主机中更改了我的heroku URL以包括https://现在图片显示。为了理解这一点,我应该查阅哪些文档?

因为
关闭
被视为字符串,而非空字符串仍然是真实的


您需要从env文件中删除
DEBUG
,以便将其设置为false(或错误值,如
DEBUG=0

本地:图像中的DEBUG True、false、on、off、no DEBUG in.env on heroku:图像中的env变量中的DEBUG设置为True。当我将其更改为False时,图像会消失。事实上,现在我正在考虑它-我认为这是因为我直接与项目一起上传文件?我在某个地方读到您想从s3或其他外部源加载媒体?我只是尝试了一系列调试设置,不管我在环境中设置了什么,图像都开始显示。好吧,我真的不知道为什么,但似乎图像无论如何都会显示出来。也使用调试0。如果将debug设置为true或false,实际的区别是什么?它只是查看允许的主机吗?但我认为它与调试变量无关。我刚才做的是-1。推到heroku 2。运行静态3。网站工作,但没有图像显示4。将环境变量调试从0更改为True-图像开始显示5。将DEBUG True更改为0,并且图像仍然正常。