What is deploying? This is a technical word for releasing your software out into the world! Instead of running your Flask webserver on localhost, you'll be able to get the code running on a machine and accessible from anywhere with an internet connection.
This repository contains the config files you'll need to deploy to Heroku. Don't copy and paste yet! We'll do that later.
Go to http://damp-meadow-68595.herokuapp.com/ (sorry, the name was generated...) and compare it to the routes and templates in this repository. Can you see when each HTML file is used?
Only one person needs to do this per team. If you'd like to share an account, pick a password you can both use!
- Go to heroku.com and create an account
- Install the Heroku Command Line Interface
cd
to the project folder in your terminal. Make sure you have a git repository pointing to this already, and if not create a repository!- Type
heroku login
and follow the instructions - Make sure you've pushed all of your changes to your normal git repository.
- Copy the following files from this repository:
- Procfile
- runtime.txt
- uwsgi.ini
- Optional: .gitignore can you guess what it does?
- Change the line that starts with
module=
inuwsgi.ini
to reflect your project. In this example, the filename, and to python this is the module name isdeploytest
, and the app name isapp
. - You can use the requirements.txt in this project, however if you've done a
pip install
for anything else then runpip freeze > requirements.txt
in your terminal to grab all the packages you've installed, and overwrite this file. This tells the server to install anything extra that it needs from pip. - In your main python file, make sure that you don't run the app when you're not executing the file, e.g.
if __name__ == '__main__':
app.run(debug=True)
# NOT app.run(debug=True) on its own!
- Almost there! Run
git push heroku
in the terminal. This pushes your code to Heroku, which will apply the changes to your (hopefully running) server. - Run
heroku open
as a shortcut to open your webpage in a browser. If there are errors, runheroku logs --tail
to have a look.
Every time you make a change, the commands you run will be as follows:
# the dot means add all changed files
git add .
git commit -m "Your message here"
# push to GitHub
git push
# push to Heroku
git push heroku