[PYTHON] I want to upload a Django app to heroku

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 environment

# DEBUG = True
DATABASES = {

django is an alias for default when no other database is selected

Use database

    '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/']

Advanced Setting

(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. a.png

result

And if you deploy with heroku and display the specified URL with a browser, it will be as follows b.png

[What you don't understand]

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. c.png

Thank you.

Recommended Posts

I want to upload a Django app to heroku
I want to make a blog editor with django admin
I want to print in a comprehension
I want to build a Python environment
How to deploy a Django app on heroku in just 5 minutes
I want to easily create a Noise Model
I want to pin Datetime.now in Django tests
I want to INSERT a DataFrame into MSSQL
How to develop a cart app with Django
I want to create a window in Python
I want to make a game with Python
I don't want to take a coding test
I want to create a plug-in type implementation
I wrote a script to upload a WordPress plugin
I want to write to a file with Python
I want to easily implement a timeout in python
I tried to create a table only with Django
I want to iterate a Python generator many times
I want DQN Puniki to hit a home run
100 image processing knocks !! (021-030) I want to take a break ...
I want to give a group_id to a pandas data frame
I want to transition with a button in flask
I want to climb a mountain with reinforcement learning
I want to write in Python! (2) Let's write a test
I want to randomly sample a file in Python
Steps from installing Python 3 to creating a Django app
I want to work with a robot in python.
I want to split a character string with hiragana
I want to install a package of Php Redis
[Python] I want to make a nested list a tuple
I want to manually create a legend with matplotlib
I want to send a business start email automatically
To myself as a Django beginner (4) --Create a memo app--
I want to run a quantum computer with Python
Deploy a web app created with Streamlit to Heroku
I want to bind a local variable with lambda
Upload a file to Dropbox
I want to solve Sudoku (Sudoku)
I want a mox generator (2)
Deploy django project to heroku
I want to create a lunch database [EP1] Django study for the first time
I want to create a lunch database [EP1-4] Django study for the first time
How to deploy a web app made with Flask to Heroku
[Django] A memorandum when you want to communicate asynchronously [Python3]
I want to start a jupyter environment with one command
[Python] I want to get a common set between numpy
I want to start a lot of processes from python
I want to make a click macro with pyautogui (desire)
I want to automatically generate a modern metal band name
NikuGan ~ I want to see a lot of delicious meat! !!
I want to make a click macro with pyautogui (outlook)
I want to use a virtual environment with jupyter notebook!
I want to install a package from requirements.txt with poetry
I want to send a message from Python to LINE Bot
[Visualization] I want to draw a beautiful graph with Plotly
I want to make input () a nice complement in python
I want to create a Dockerfile for the time being.
I want to understand systemd roughly
Implement a Django app on Hy
I want to scrape images to learn
I want to do ○○ with Pandas