-1

I have recently gone through this flask tutorial and am now attempting to deploy my application to heroku.

I am able to run the app locally using the command gunicorn "platform:create_app()". Due to that command working I added a Procfile which contains web: gunicorn platform.'create_app()' but when I try to deploy to Heroku I'm receiving the error ModuleNotFoundError: No module named 'platform.create_app()'.

Tgumtree
  • 11
  • 3

1 Answers1

0

I searched around and couldn't find a really clear answer to this question, although I think this thread and specifically this answer might help to shed some light.

What I can tell you is that none of the Procfiles I have ever created for Flask apps to deploy in Heroku contained .py or parentheses.

A typical Procfile for me looks like this:

web: gunicorn app:app

Then in the same directory is the main app file app.py that contains a line:

app = Flask(__name__)

As far as I can tell the first app in the command points to the file (module) app.py, and the second to the variable app that is defined as Flask(__name__).


So for your case the following should work:

web: gunicorn platform:app

Assuming you have a Python module named platform.py and then inside that file you would need to have a line

app = create_app()

The create_app() function in the tutorial you referenced returns a Flask object so that should do the job.

ljdyer
  • 1,946
  • 1
  • 3
  • 11
  • Thanks for your response, I think part of the issue is that my file which would be called platform.py is actually ```__init__.py``` as per the tutorial I followed. I'm not too sure how to reference this ```__init__.py``` file in the Procfile. ```web: gunicorn __init__:app``` doesn't seem right. – Tgumtree Jan 14 '22 at 07:46
  • `__init__.py` is in a folder `flaskr` relative to the base directory containing the Procfile, right? Create a file `app.py` in the base directory containing: `from flaskr import create_app` and `app = create_app()`, then use web: gunicorn app:app` for the Procfile. – ljdyer Jan 14 '22 at 07:53