My django web with heroku keeps having errors

Hi Campers! I’ve been building my portfolio web page with Django. It wasn’t that complicated and I made it simple. However the real part started once I wanted to deploy my web with Heroku which I already used for deploying my node.js webs.

I can run with “heroku local” and it runs fine also when I use runserver in virtualenv but there’s same errors and I’ve searched for the solutions whole day but I couldn’t.

2021-02-16T20:26:35.823862+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-02-16T20:26:35.823862+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-02-16T20:26:35.823863+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
2021-02-16T20:26:35.823863+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
2021-02-16T20:26:35.823863+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
2021-02-16T20:26:35.823864+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 991, in _find_and_load
2021-02-16T20:26:35.823864+00:00 app[web.1]: File "<frozen importlib._bootstrap>", line 973, in _find_and_load_unlocked
2021-02-16T20:26:35.823864+00:00 app[web.1]: ModuleNotFoundError: No module named 'portfolio'
2021-02-16T20:26:35.824001+00:00 app[web.1]: [2021-02-16 20:26:35 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-02-16T20:26:35.856818+00:00 app[web.1]: [2021-02-16 20:26:35 +0000] [4] [INFO] Shutting down: Master
2021-02-16T20:26:35.856905+00:00 app[web.1]: [2021-02-16 20:26:35 +0000] [4] [INFO] Reason: Worker failed to boot.
2021-02-16T20:26:35.918015+00:00 heroku[web.1]: Process exited with status 3
2021-02-16T20:26:35.980096+00:00 heroku[web.1]: State changed from starting to crashed
2021-02-16T20:26:36.601488+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=poianakim.herokuapp.com request_id=93a834d5-7212-499d-9f98-f02936bc7459 fwd="95.239.217.192" dyno= connect= service= status=503 bytes= protocol=https
2021-02-16T20:26:37.057729+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=poianakim.herokuapp.com request_id=34840aae-ab2d-49d5-8143-df2f0d30d8bf fwd="95.239.217.192" dyno= connect= service= status=503 bytes= protocol=https
2021-02-16T20:26:37.548866+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=poianakim.herokuapp.com request_id=5055a2e6-cd2f-4b3d-8886-2eac26b19075 fwd="95.239.217.192" dyno= connect= service= status=503 bytes= protocol=https

I think significant line would be

ModuleNotFoundError: No module named 'portfolio'

portfolio is my project name and there are several apps

This is my file tree and I managed to put requirements.txt and runtime.txt beside to venv directory since that is the root of git repo. and I had to move Procfile into the venv since the former structure caused error.

psycopg2-binary==2.8.6
asgiref==3.3.1
dj-database-url==0.5.0
Django==3.1.6
gunicorn==20.0.4
numpy==1.20.1
pandas==1.2.2
Pillow==8.1.0
python-dateutil==2.8.1
python-dotenv==0.15.0
pytz==2021.1
six==1.15.0
sqlparse==0.4.1
whitenoise==5.2.0
requests==2.25.1

This is my requirements. txt

and gitignore file with

env
# Text backup files
*.bak

#Database
*.sqlite3

python version is 3.8.5 and it’s supported by heroku
It’s been deployed and built but the Application error makes me crazy

I really wish there’s someone who can help me!!

@kby906 It can be frustrating when your application is working fine on your desktop then breaks when trying to run it on Heroku. I can give you some advice.

On your desktop you can install the Heroku cli application then you can see the logs in real time by running this command.

heroku logs --tail --app <name_of_your_application>

It is very helpful, then look up and errors you see in the log files.

Another thing is that Heroku does load the .env file. You will have to configure python-dotenv to load the .env variables on Heroku.

As a last resort, you can delete what you have on Heroku and upload it again. It might be a corrupt file somewhere on Heroku.

It looks like your whole project is in the venv directory. Is it supposed to be like that on in the portfolio directory? I have not used Django I am not sure about the folder structure.

Hopefully someone else will have more insight about getting deployed on heroku specifically, but your error

indicates that whichever server you have serving your app is not able to find your python module portfolio on the python path, so you will need to configure that program to include your app on its python path. I’ve seen similar errors while configuring an app to deploy with apache2/mod_wsgi. There’s no way to tell you how to proceed without knowing how you are serving your app and the contents of the configuration files and settings.py (minus your secret key!).

I did notice that there is a lot of documentation on heroku for deploying django and a lot of it seems to use some of their packages, so you may be best starting from scratch and following one of their guides as closely as possible.

Good luck.

Thank you for the reply @brandon_wallace , @jeremy.a.gray !
I’ve git init inside of the directory portfolio then deployed again then it finally worked. Though I still have a problem with DB but still, there was a progress. Eventually I should have deployed from the root dircectory not including venv. It was my first django deployment with heroku and other experiences with node.js there wasn’t error or problem like this time so I didn’t know it.

Anyway, If somebody have a same problem while deploying with heroku you could try to deploy in this way!

1 Like