Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 调试=False时出现服务器错误500_Python_Django_Heroku_Deployment - Fatal编程技术网

Python 调试=False时出现服务器错误500

Python 调试=False时出现服务器错误500,python,django,heroku,deployment,Python,Django,Heroku,Deployment,我正在尝试使用Django将web应用程序部署到Heroku。我可以在本地运行该应用程序,但当我尝试使用DEBUG=False实时加载它时,会出现服务器500错误。如果我将设置更改为DEBUG=True,它会工作。我将感谢任何帮助 编辑: 这帮助我获得了错误的电子邮件版本,即缺少“home/css/bootswatch.css”的staticfiles清单条目。。所以现在我担心的是静态文件没有正确配置,但我不知道如何修复它们。我在禁用collectstatic的情况下使用它-我必须这样做才能让应

我正在尝试使用Django将web应用程序部署到Heroku。我可以在本地运行该应用程序,但当我尝试使用
DEBUG=False
实时加载它时,会出现服务器500错误。如果我将设置更改为
DEBUG=True
,它会工作。我将感谢任何帮助

编辑: 这帮助我获得了错误的电子邮件版本,即缺少“home/css/bootswatch.css”的staticfiles清单条目。。所以现在我担心的是静态文件没有正确配置,但我不知道如何修复它们。我在禁用
collectstatic
的情况下使用它-我必须这样做才能让应用部署。这可能是问题所在吗?我记不起我必须运行的确切命令,但基本上heroku告诉我,在我禁用
collectstatic
之前,它无法部署应用程序。

*新编辑: ,我意识到我必须删除禁用的collectstatic配置变量,然后再次尝试构建。没用。这个错误使我意识到,初学者模板附带的默认静态文件必须位于设置模块内。做了那件事,推了推——还是不起作用。回溯显示我的字体css文件有问题。删除了文件,添加了CDN,然后按下并弹出。现场工程。我希望这对将来的其他人有所帮助

错误日志

2017-10-08T19:33:03.000000+00:00 app[api]: Build started by user me@email.com
2017-10-08T19:33:19.148973+00:00 heroku[web.1]: Restarting
2017-10-08T19:33:19.149620+00:00 heroku[web.1]: State changed from up to starting
2017-10-08T19:33:19.717815+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2017-10-08T19:33:19.732436+00:00 app[web.1]: [2017-10-08 19:33:19 +0000] [4] [INFO] Handling signal: term
2017-10-08T19:33:19.732487+00:00 app[web.1]: [2017-10-08 19:33:19 +0000] [8] [INFO] Worker exiting (pid: 8)
2017-10-08T19:33:19.732716+00:00 app[web.1]: [2017-10-08 19:33:19 +0000] [9] [INFO] Worker exiting (pid: 9)
2017-10-08T19:33:19.833095+00:00 app[web.1]: [2017-10-08 19:33:19 +0000] [4] [INFO] Shutting down: Master
2017-10-08T19:33:20.012423+00:00 heroku[web.1]: Process exited with status 0
2017-10-08T19:33:18.676112+00:00 app[api]: Release v30 created by user me@email.com
2017-10-08T19:33:18.676112+00:00 app[api]: Deploy 8f625678 by user me@email.com
2017-10-08T19:33:03.000000+00:00 app[api]: Build succeeded
2017-10-08T19:33:29.936137+00:00 heroku[web.1]: Starting process with command `gunicorn portfolio.wsgi`
2017-10-08T19:33:32.419548+00:00 app[web.1]: [2017-10-08 19:33:32 +0000] [4] [INFO] Starting gunicorn 19.6.0
2017-10-08T19:33:32.420072+00:00 app[web.1]: [2017-10-08 19:33:32 +0000] [4] [INFO] Listening at: http://0.0.0.0:23534 (4)
2017-10-08T19:33:32.420207+00:00 app[web.1]: [2017-10-08 19:33:32 +0000] [4] [INFO] Using worker: sync
2017-10-08T19:33:32.424142+00:00 app[web.1]: [2017-10-08 19:33:32 +0000] [8] [INFO] Booting worker with pid: 8
2017-10-08T19:33:32.523409+00:00 app[web.1]: [2017-10-08 19:33:32 +0000] [9] [INFO] Booting worker with pid: 9
2017-10-08T19:33:33.592588+00:00 heroku[web.1]: State changed from starting to up
2017-10-08T19:33:33.991800+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=89d87c81-0ab1-4b
2e-8705-43ef55710082 fwd="my.public.ip.address" dyno=web.1 connect=0ms service=225ms status=500 bytes=234 protocol=https
2017-10-08T19:33:36.569500+00:00 heroku[router]: at=info method=GET path="/" host=myproject.herokuapp.com request_id=cb8ea686-89ba-44
0f-8e66-0c3258c2de92 fwd="my.public.ip.address" dyno=web.1 connect=0ms service=42ms status=500 bytes=234 protocol=https

文件夹结构:

  • 计划
    • 应用程序
    • 应用程序
    • 计划
      • 背景
        • __初始值
        • 基本设置.py
        • 本地_settings.py
        • 生产设置.py
      • manage.py

\uuuuuuuuuuuuuu.py

from .base_settings import *
from .production_settings import *

try:
    from .local_settings import *
except:
    pass
import os, dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

DEBUG = ""


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'app ',
    'app',
]

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 = 'project.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',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'project.wsgi.application'


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

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',
    },
]


LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Change 'default' database configuration with $DATABASE_URL.
DATABASES['default'].update(dj_database_url.config(conn_max_age=500))

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['myproject.herokuapp.com', 'localhost']

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

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
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.storage.CompressedManifestStaticFilesStorage'
from .base_settings import *

SECRET_KEY = 'mysecretkey'

DEBUG = True
from .base_settings import *

SECRET_KEY = os.environ.get('SECRET_KEY')

DEBUG = False

基本设置.py

from .base_settings import *
from .production_settings import *

try:
    from .local_settings import *
except:
    pass
import os, dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

DEBUG = ""


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'app ',
    'app',
]

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 = 'project.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',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'project.wsgi.application'


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

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',
    },
]


LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Change 'default' database configuration with $DATABASE_URL.
DATABASES['default'].update(dj_database_url.config(conn_max_age=500))

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['myproject.herokuapp.com', 'localhost']

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

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
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.storage.CompressedManifestStaticFilesStorage'
from .base_settings import *

SECRET_KEY = 'mysecretkey'

DEBUG = True
from .base_settings import *

SECRET_KEY = os.environ.get('SECRET_KEY')

DEBUG = False

本地设置.py

from .base_settings import *
from .production_settings import *

try:
    from .local_settings import *
except:
    pass
import os, dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

DEBUG = ""


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'app ',
    'app',
]

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 = 'project.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',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'project.wsgi.application'


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

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',
    },
]


LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Change 'default' database configuration with $DATABASE_URL.
DATABASES['default'].update(dj_database_url.config(conn_max_age=500))

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['myproject.herokuapp.com', 'localhost']

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

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
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.storage.CompressedManifestStaticFilesStorage'
from .base_settings import *

SECRET_KEY = 'mysecretkey'

DEBUG = True
from .base_settings import *

SECRET_KEY = os.environ.get('SECRET_KEY')

DEBUG = False

生产设置.py

from .base_settings import *
from .production_settings import *

try:
    from .local_settings import *
except:
    pass
import os, dj_database_url

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

DEBUG = ""


INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    # Disable Django's own staticfiles handling in favour of WhiteNoise, for
    # greater consistency between gunicorn and `./manage.py runserver`. See:
    # http://whitenoise.evans.io/en/stable/django.html#using-whitenoise-in-development
    'whitenoise.runserver_nostatic',
    'django.contrib.staticfiles',
    'app ',
    'app',
]

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 = 'project.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',
            ],
            'debug': DEBUG,
        },
    },
]

WSGI_APPLICATION = 'project.wsgi.application'


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

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',
    },
]


LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Change 'default' database configuration with $DATABASE_URL.
DATABASES['default'].update(dj_database_url.config(conn_max_age=500))

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

# Allow all host headers
ALLOWED_HOSTS = ['myproject.herokuapp.com', 'localhost']

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

STATIC_ROOT = os.path.join(PROJECT_ROOT, 'staticfiles')
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.storage.CompressedManifestStaticFilesStorage'
from .base_settings import *

SECRET_KEY = 'mysecretkey'

DEBUG = True
from .base_settings import *

SECRET_KEY = os.environ.get('SECRET_KEY')

DEBUG = False

据我所知,当
DEBUG=False
时,唯一的问题是
ALLOWED\u HOSTS
设置。关闭调试后,Django将对照列表检查主机名,如果主机不在允许列表中,则拒绝请求

它通常会得到400分,但如果遇到进一步的问题,则可以得到500分: ,我意识到我必须删除禁用的collectstatic配置变量,然后再次尝试构建。没用。这个错误使我意识到,初学者模板附带的默认静态文件必须位于设置模块内。做了那件事,推了推——还是不起作用。回溯显示我的字体css文件有问题。删除了文件,添加了CDN,然后按下并弹出。现场工程。我希望这对将来的其他人有所帮助