Python Flask on Heroku

Playground 1

How to create a Flask service on Heroku

1.  Install the Virtual Env
$ pip install  virtualenv

2.  Set up a virtual Environment - This limits the dependencies you needed to run the project
$ virtualenv venv

3. Activate Virtrual environment
$ source venv/bin/activate

4. Install Flask
$ pip install Flask

5. Create a sample Program to verify on local


 $ python app.py
 * Running on http://localhost:5000/

Running Flask on local
For Heroku, you need to specify the port and the environment


6. Change Code to work on Heroku


7.  Declare the depencies
$ pip freeze > requirements.txt

8.  Specify the Procfile

A Procfile is a text file in the root directory of your application that defines process types and explicitly declares what command should be executed to start your app.

$vi Procfile

Insert this line:
web: python app.py

9.  Login to Heroku
$ heroku login

10.  Create the app on Heroku
$ heroku create

11.  Start Deployment
$ git add.
$ git commit -m "new python"
$ git push heroku master

12. That's it!  Now run your service
$ heroku open




コメント

人気の投稿