flask hello world application
Steps to deploy a static Flask website to Heroku
- Create an account on www.heroku.com if you don't have one already.
- Download and install Heroku Toolbelt from www.toolbelt.heroku.com/
- Install gunicorn with "pip install gunicorn". Make sure you're using pip from your virtual environment if you have one.
- Create a requirement.txt file in the main app directory where the main Python app file is located. You can create that file by running "pip freeze > requirements.txt" in the command line. Make sure you're using pip from your virtual environment if you have one. The requirement.txt file should now contain a list of Python packages.
- Create a file named "Procfile" in the main app directory. The file should not contain any extension. Then type in this line inside: "web: gunicorn script1:app" where "script1" should be replaced with the name of your Python script and "app" with the name of the variable holding your Flask app.
- Create a runtime.txt file in the main app directory and type "python-3.5.1" inside. If you're using Python 2, you may want to type in "python-2.7.11" instead.
- Open your computer terminal/command line to point to the directory where the Python file containing your app code is located.
- Using the terminal, log in to Heroku with "heroku login"
- Enter your Heroku email address
- Enter your Heroku password
- Create a new Heroku app with "heroku create myawesomeappname"
- Initialize a local git repository with "git init"
- Add your local application files to git with "git add ."
- Tell git your email address with "git config --global user.email "[email protected]"". Make sure the email address is inside quotes here.
- Tell git your username (just pick whatever username) with "git config --global user.name "whateverusername"". The username should be in quotes.
- Commit the changes with "git commit -m "first commit"". Make sure "first commit" is inside quotes.
- Before pushing the changes to Heroku, tell heroku the name of the app you want to use with heroku "git:remote --app myawesomeappname"
- Push the changes to Heroku with "git push heroku master"
- That should do it. Go ahead and open your app with "heroku open".