I'm hoping you may be able to help me and at the same time, I hope this query may serve others here well in the future.
Based on the excellent book: Python Crash Course by Eric Matthes, I am trying to deploy a Django app to Heroku with the use of Git and have come across several issues. Do note, there are some corrections to the book here: https://ehmatthes.github.io/pcc/updates.html
I am specifically mentioning the book here, as I believe it to be ranked one of the best starter books on various sites, so I can imagine other people facing the same problems - also, as there are several posts related to these 3 topics.
Initially, the app could be commited to Git, but then not pushed to Heroku using:
git push heroku master
Part 1: This contineously brought about the error:
No Procfile and no package.json file found in Current Directory - See heroku local --help
To resolve this, it was vital to make sure the file had no extension (mac os) did not show it, but an ls in the directory showed the .txt ending on the file.
Part 2: Retrying this, now allowed for a new message:
ModuleNotFoundError: no module named 'bootstrap3"
This could be resolved by making sure the django-bootstrap3==6.x.x requirement was available in the requirements.txt file when the command:
pip freeze > requirements.txt
was issued - manually adding it did not do the trick. In addition, I manually added:
appdirs==1.4.3
Next, I followed the instructions on an website instructing on how to disable collect static:
heroku config:set DISABLE_COLLECTSTATIC=1
This combination has gotten me a step further.
Part 3 All this done, I was now able to succesfully run the code:
git push heroku master
However, running:
heroku ps
directly afterwards, shows a crash
web.1: crashed 2018/12/09 11:24:35 +0100 (~ 42m ago)
trying to migrate the database using the below command:
heroku run python manage.py migrate
now let's me know, it is missing the module: dj-database-url
ModuleNotFoundError: No module named 'dj_database_url'
Looking at my requirements.txt file though, I clearly have this in the list here.
Since the primary references in the net are either to check it is included in the requirements.txt file, the gunicorn file is defined correctly or collectstatic is disabled - I am at a loss and I hope someone might be able to help with this as well as hoping, the above pointers will benefit others dealing with the same early problems.
My files look as follows:
Procfile
web: gunicorn learning_log.wsgi —-log-file -
Procfile is with a capital "P" and the application is called learning_log
requirements.txt
astroid==2.1.0
autopep8==1.4.3
dj-database-url==0.5.0
dj-static==0.0.6
Django==2.1.3
gunicorn==19.9.0
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pycodestyle==2.4.0
pylint==2.2.2
pytz==2018.7
six==1.11.0
static3==0.7.0
wrapt==1.10.11
django-bootstrap3==6.2.2
psycopg2>=2.6.1
appdirs==1.4.3
wsgi.py
import os
from django.core.wsgi import get_wsgi_application
from whitenoise.django import DjangoWhiteNoise
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "learning_log.settings")
application = get_wsgi_application()
application = DjangoWhiteNoise(application)
snip from the settings.py-file:
# Settings for django-bootstrap3
BOOTSTRAP3 = {
'include_jquery': True,
}
# Heroku Settings
cwd = os.getcwd()
print("--- CWD ---\n", cwd, "\n---\n")
if cwd == '/app' or cwd[:4] == '/tmp':
import dj_database_url
DATABASES = {
'default': dj_database_url.config(default='postgres://localhost')
}
# 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 = ['*']
# Static asset configuration
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
runtime.txt
python-3.7.0
I sincerely hope, someone may be able to help here - I'm at a bit of a loss as to what else may be required.
I hope this is sufficient to explain - I understand that apparently there were also some updates on Heroku's side, but to learn this is really difficult.
Many thanks, Simon
Ok, after lot's and lot's of testing - I finally realized that the requirement file kept changing (I am pretty certain, not only when I ran freeze).
As a result, several packages previously installed were no longer in the requirements.txt file. Essentially this means, this error really was down to the requirements.txt file beeing complete and having ALL required packages in it.
My final package list was as follows:
appdirs==1.4.3
astroid==2.0.4
certifi==2018.8.24
chardet==3.0.4
cycler==0.10.0
Django==2.1.1
django-bootstrap3==11.0.0
dj-database-url==0.5.0
dj-static==0.0.6
gunicorn==19.3.0
idna==2.7
isort==4.3.4
kiwisolver==1.0.1
lazy-object-proxy==1.3.1
matplotlib==2.2.2
mccabe==0.6.1
numpy==1.15.0
psycopg2>=2.6.1
pygal==2.4.0
pygal-maps-world==1.0.2
pygame==1.9.4
pylint==2.1.1
pyparsing==2.2.0
python-dateutil==2.7.3
pytz==2018.5
requests==2.19.1
six==1.11.0
static3==0.6.1
urllib3==1.23
virtualenv==16.0.0
whitenoise==4.1.2
wrapt==1.10.11