Home>

I want to publish a WebApp using HerokuGit, but I'm in trouble with two errors.
・ Error when pushing to remote
・ 400BadRequest

[Reasons for using HerokuGit (Reasons for not using GitHub)]
Publish WebApp via GitHub is something that was done before,
This time, we create a remote repository on Heroku and aim to release the app.
I have code and data that I don't want to go outside, so I don't want to publish apps via GitHub's public repository.

[How to proceed]
We proceeded with the work referring to the following page. This is fine when deploying via GitHub.
Heroku deployment instructions with Django 2.0

Error message

・ Error pushing to HerokuGit

remote: FileNotFoundError: [Errno 2] No such file or directory: '/ tmp/build_1f1d6b65dcb127cece6acd573026910d/static'
remote:
remote:! Error while running '$python manage.py collectstatic --noinput'.
remote: See traceback above for details.
remote:
remote: You may need to update application code to resolve this error.
remote: Or, you can disable collectstatic for this application:
remote:
remote: $heroku config: set DISABLE_COLLECTSTATIC = 1
remote:
remote: https://devcenter.heroku.com/articles/django-assets
remote:! Push rejected, failed to compile Python app.
remote:
remote:! Push failed
remote: Verifying deploy ...
remote:
remote:! Push rejected to webjti.
remote:
To https://git.heroku.com/webjti.git
 [remote rejected] master->master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/webjti.git'


→ Deploy Django API on heroku (your own memo) Implemented because there was a solution.heroku config: set DISABLE_COLLECTSTATIC = 1
→ This error can be avoided, but 400 errors
→ Django gives Bad Request (400) when DEBUG = False Django 400 error is about messing with settings.py
→ 400 continues to come out

Applicable source code

The following code will be released.
・ Three kinds of sacred treasures (Procfile, requirements.txt, runtime.txt)
・ Django settings files (wigs.py, settings.py)
・ .Gitignore file

Three kinds of sacred

# Procfile
web: gunicorn config.wsgi --log-file-
# requirements.txt
dj-database-url == 0.5.0
dj-static == 0.0.6
Django == 2.1
django-toolbelt == 0.0.1
gunicorn == 19.9.0
psycopg2 == 2.7.5
pytz == 2018.5
static3 == 0.7.0
whitenoise == 4.0
# runtime.txt
python-3.6.4


・ Django configuration file

# wigs.py
import os
from dj_static import Cling
from django.core.wsgi import get_wsgi_application
os.environ.setdefault ('DJANGO_SETTINGS_MODULE', 'config.settings')
application = Cling (get_wsgi_application ())
# settings.py
import os
# Build paths inside the project like this: os.path.join (BASE_DIR, ...)
BASE_DIR = os.path.dirname (os.path.dirname (os.path.abspath (__ file__)))
PROJECT_NAME = os.path.basename (BASE_DIR)
# Quick-start development settings-unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'r6mcj3edhf6fk_9iw61 # 7zqe2) vqvn ^ hw (q9g @ rs5)-# l (mn8r'
# SECURITY WARNING: don't run with debug turned on in production!
from socket import gethostname
hostname = gethostname ()
if "USERNAME" in hostname:
    # Debug environment
    DEBUG = True
    DATABASES = {
        'default': {
            'ENGINE': 'django.db.backends.sqlite3',
            'NAME': os.path.join (BASE_DIR, 'db.sqlite3'),
        }
    }
    ALLOWED_HOSTS = [] # I'm not sure but this is also important
else:
    # Production environment
    DEBUG = False
    LOGGING = {
        'version': 1,
        'disable_existing_loggers': False,
        'handlers': {
            'console': {
                'class': 'logging.StreamHandler',
            },
        },
        'loggers': {
            'django': {
                'handlers': ['console'],
                'level': os.getenv ('DJANGO_LOG_LEVEL', 'DEBUG'),
            },
        },}
    # DB setting
    import dj_database_url
    PROJECT_ROOT = os.path.dirname (os.path.abspath (__ file__))
    db_from_env = dj_database_url.config ()
    DATABASES = {
        'default': dj_database_url.config ()
    }
    ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
    'shisan.apps.ShisanConfig',
    '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', # added
    '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 = 'config.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 = 'config.wsgi.application'

# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join (BASE_DIR, 'db.sqlite3'),
    }
}

# Password validation
# https://docs.djangoproject.com/en/2.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/2.1/topics/i18n/
LANGUAGE_CODE = 'ja'
TIME_ZONE = 'Asia/Tokyo'
USE_I18N = True
USE_L10N = True
USE_TZ = True

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/
STATIC_URL = '/ static /'
STATICFILES_DIRS = [os.path.join (BASE_DIR, 'static')]
STATIC_ROOT = os.path.join (BASE_DIR, 'static_root')


.Gitignore

venv
__pycache__
staticfiles
db.sqlite3
* .py [co]
Tried

・ heroku git: remote -a
When I want to create a remote in HerokuGit, there was a description of$heroku git: remote -a APPNAME, so delete the repository and then$heroku git: remote -a again Or APPNAME. However, there is no change.
* Static file origin?
When deploying Django app to Heroku, collectstatic is automatically executed
When reading, it is written that things that can't be read, such as being irrelevant to Collectstatic without a static file.
I don't have a static file at the moment, so I think it might be suspicious. (Try it now)

Supplemental information (FW/tool version etc.)

MacOS High Sierra 10.13.6
Python 3.6.4
Django2.1

If i have any other questions, please contact us.