Reputation: 481
My application runs normally when running using python run.py
but when running using gunicorn gunicorn run:app
it gives 'flask_cors' module not found error.
I have created a basic application to make it easier to understand, I have debugged it a lot but didn't work, as it's running fine with python run.py
so it should be running when using gunicorn, I think I do not actually understand how gunicorn is actually importing that it's leading to this error.
Working Directory
.
├── flaskblog
│ ├── __init__.py
│ └── routes.py
├── requirements.txt
└── run.py
1 directory, 4 files
__init__.py
file
from flask import Flask
from flask_cors import CORS
app = Flask(__name__)
CORS(app, support_credentials=True)
from flaskblog import routes
routes.py file
from flaskblog import app
from flask_cors import cross_origin
@app.route("/")
@cross_origin(supports_credentials=True)
def home():
return "home"
run.py file
from flaskblog import app
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')
requirements.txt
Flask
gunicorn
flask-cors
edit:
I run the program again to get the error trace, and this time it worked?
It started at '127.0.0.1:8000' so I used gunicorn -b 0.0.0.0 run:app
How is it working now?
If you have a better title for the question then please edit it, as now my issue is it's strange behaviour.
Upvotes: 1
Views: 1105
Reputation: 481
Deleted the pycache and created the environment again, this time it worked as it should be and hosted on heroku successfully. Inside my procfile
web: gunicorn gettingstarted.wsgi
web: gunicorn run:app
Upvotes: 2