KeyError 'OPTIONS' при попытке запустить Django проект Heroku локально - PullRequest
0 голосов
/ 10 апреля 2020

В настоящее время я пытаюсь запустить свой проект Django Heroku локально для разработки после внесения локальных изменений. При выдаче команды heroku local я получаю сообщение об ошибке, показанное ниже.

Я полагаю, что мне не хватает какой-либо конфигурации локальной среды, так как в моем производственном развертывании все работает как положено.

Ниже сообщения об ошибке находится мой settings.py файл.

12:05:35 PM web.1 |  [2020-04-10 12:05:35 -0500] [3553] [ERROR] Exception in worker process
12:05:35 PM web.1 |  Traceback (most recent call last):
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
12:05:35 PM web.1 |      worker.init_process()
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
12:05:35 PM web.1 |      self.load_wsgi()
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
12:05:35 PM web.1 |      self.wsgi = self.app.wsgi()
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
12:05:35 PM web.1 |      self.callable = self.load()
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
12:05:35 PM web.1 |      return self.load_wsgiapp()
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
12:05:35 PM web.1 |      return util.import_app(self.app_uri)
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/gunicorn/util.py", line 358, in import_app
12:05:35 PM web.1 |      mod = importlib.import_module(module)
12:05:35 PM web.1 |    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
12:05:35 PM web.1 |      return _bootstrap._gcd_import(name[level:], package, level)
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 983, in _find_and_load
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap_external>", line 728, in exec_module
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
12:05:35 PM web.1 |    File "/Users/ben/PersonalCode/simple-foodie-api/simpleFoodie/wsgi.py", line 16, in <module>
12:05:35 PM web.1 |      application = get_wsgi_application()
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/django/core/wsgi.py", line 12, in get_wsgi_application
12:05:35 PM web.1 |      django.setup(set_prefix=False)
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/django/__init__.py", line 19, in setup
12:05:35 PM web.1 |      configure_logging(settings.LOGGING_CONFIG, settings.LOGGING)
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/django/conf/__init__.py", line 76, in __getattr__
12:05:35 PM web.1 |      self._setup(name)
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/django/conf/__init__.py", line 63, in _setup
12:05:35 PM web.1 |      self._wrapped = Settings(settings_module)
12:05:35 PM web.1 |    File "/Library/Python/3.7/site-packages/django/conf/__init__.py", line 142, in __init__
12:05:35 PM web.1 |      mod = importlib.import_module(self.SETTINGS_MODULE)
12:05:35 PM web.1 |    File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
12:05:35 PM web.1 |      return _bootstrap._gcd_import(name[level:], package, level)
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 983, in _find_and_load
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap_external>", line 728, in exec_module
12:05:35 PM web.1 |    File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
12:05:35 PM web.1 |    File "/Users/ben/PersonalCode/simple-foodie-api/simpleFoodie/settings.py", line 138, in <module>
12:05:35 PM web.1 |      del DATABASES['default']['OPTIONS']['sslmode']
12:05:35 PM web.1 |  KeyError: 'OPTIONS'
"""
Django settings for simpleFoodie project.

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

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

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

import os
import dj_database_url
import dotenv
import django_heroku

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

# This is new:
dotenv_file = os.path.join(BASE_DIR, ".env")
if os.path.isfile(dotenv_file):
    dotenv.load_dotenv(dotenv_file)

PROJECT_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(PROJECT_DIR, 'static')

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

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

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = ['0.0.0.0', 'localhost', '127.0.0.1', 'https://protected-retreat-27678.herokuapp.com/',
                 'protected-retreat-27678.herokuapp.com', 'https://simple-foodie-api.herokuapp.com/', 'simple-foodie-api.herokuapp.com']


# Application definition

INSTALLED_APPS = [
    'recipes.apps.RecipesConfig',
    'rest_framework',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

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 = 'simpleFoodie.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 = 'simpleFoodie.wsgi.application'


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

DATABASES = {}
DATABASES['default'] = dj_database_url.config(conn_max_age=600)

STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'

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

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'America/Chicago'

USE_I18N = True

USE_L10N = True

USE_TZ = True


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

REST_FRAMEWORK = {
    'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.PageNumberPagination',
    'PAGE_SIZE': 10
}

# This should already be in your settings.py
django_heroku.settings(locals())# This is new
del DATABASES['default']['OPTIONS']['sslmode']
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...