It's quite difficult.
Error encountered in $ heroku logs --tail
error code=H10 desc="App crashed"
error code=h14 desc="no web processes running"
Such.
Even if each is treated with Stackoverflow etc., it will not be solved.
However, it worked well in the following way.
$ virtualenv flaskapp
$ cd flaskapp
$ source bin/activate
$ (flaskapp) $
For example
$ (flaskapp) $ pip install requests
$ (flaskapp) $ pip install Flask
Toka Toka.
Here, gunicorn and Flask are installed.
$ (flaskapp) $ pip3 install Flask gunicorn
[Gunicorn reference]: Gunicorn is a WSGI (Web Server Gateway Interface) HTTP Server of python and is a derivative of Unicorn of Ruby. Gunicorn is a lightweight server with a very simple implementation compared to various frameworks. Reference: https://qiita.com/arata-honda/items/09e1c350b1bd8a186e9c [How to use] Install gunicorn with pip install gunicorn, Start with gunicorn hello: app.
Assuming you've signed in on Heroku
$ (flaskapp) $ wget -qO- https://cli-assets.heroku.com/install-ubuntu.sh | sh
$ (flaskapp) $ heroku login
$ echo "web: gunicorn app:app --log-file -" > Procfile
$ (flaskapp) $ pip3 freeze > requirements.txt
Click==7.0
Flask==1.1.1
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.10.3
MarkupSafe==1.1.1
Werkzeug==0.16.0
--runtime.txt (optional)
$ (flaskapp) $ python -V | sed -n "s/Python /python-/p" > runtime.txt
from flask import Flask
import os
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == "__main__":
app.run(host="0.0.0.0", port=int(os.environ.get("PORT", 5000)))
Miso is not just app.run () here.
At this point, check if it works locally.
$ (flaskapp) $ python app.py
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
$ curl http://127.0.0.1:5000
Hello World!
$ (flaskapp) $ git init
$ (flaskapp) $ echo "*.DS_Store" > .gitignore
$ (flaskapp) $ git add .
$ (flaskapp) $ git commit -m 'first commit'
$ (flaskapp) $ heroku create
$ (flaskapp) $ git push heroku master
Another screen opened and Hello World was displayed safely.
Even if I add a static folder
that is often used in Flask to the app and deploy it on Heroku, it cannot be created on heroku. The reason is that git ignores empty folders.
If you put the files in the static folder and then deploy it, a static folder will be created.
Reference: [Complete version] Procedure for deploying API created with Flask to Heroku (Note) Reference: [Error: No such file or directory:'/ app / {myappname} / static'”](https://stackoverflow.com/questions/19323513/heroku-django-oserror-no-such-file-or- directory-app-myappname-static)
Recommended Posts