Thank you for your help.
【environment】 Surface Laptop2 Windows 1809 Python 3.7.4 (the one running on the command line) Django 2.2.6
[What I want to achieve] I want to publish an app made with Django using heroku
【Status】 I'm having trouble deploying to Heroku with the Django app and the build isn't successful.
[Procedures performed](URLs referred to, etc.) (1) https://qiita.com/frosty/items/66f5dff8fc723387108c https://qiita.com/RyuSA/items/0cbc7d5b0145585861a8 I rewrote settings.py with reference to these two sites. Was rewritten as follows from socket import gethostname # You can get the host name by doing this *** A import django_heroku import os import dj_database_url
hostname = gethostname () # Assign the host name obtained by A to hostname
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
INSTALLED_APPS = [ 'polls.apps.PollsConfig', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ]
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', Added'whitenoise.middleware.WhiteNoiseMiddleware', # ← ]
ROOT_URLCONF = 'mysite.urls'
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [os.path.join(BASE_DIR, '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 = 'mysite.wsgi.application'
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
DEBUG = False if not DEBUG: SECRET_KEY = os.environ['SECRET_KEY']
DEBUG = False
try: from .local_settings import * # Importing all of the loca_settings module except ImportError: pass
STATIC_URL = '/static/' STATIC_ROOT = 'staticfiles' STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
if "DESKTOP-877IM6E" in hostname:
# DEBUG = True
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
ALLOWED_HOSTS = ['*'] #Because it is a local development environment, there is no need for a domain else: DEBUG = False db_from_env = dj_database_url.config() DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'name', 'USER': 'user', 'PASSWORD': '', 'HOST': 'host', 'PORT': '', } } ALLOWED_HOSTS = ['https://salty-beyond-49092.herokuapp.com/']
(2) As shown in the image below, the file is set, and requirements.txt and Procfile are set. Also, the one covered in black in the image is your PC name.
And if you deploy with heroku and display the specified URL with a browser, it will be as follows
I'm new to Django and have no idea why I get a Bad request. I haven't got any errors, so I don't know where to fix it. For developer tool error messages, 「Failed to load resource: the server responded with a status of 400 (Bad Request)」 An error message like this is displayed. Even if you look at heroku status as shown in the image below It seems that there is no problem with the database etc.
Thank you.
Recommended Posts