Fork this repository on GitHub.
Clone your forked repository to your local file system.
Update runtime.txt to the version of python you are using. You can find out the version by using python -V
or python3 -V
(for Python3). Your runtime.txt file should look like python-<VERSION NUMBER>
.
Rename the secret.py.example
file to the secret.py
. Use cp secret.py.example secret.py
or mv secret.py.example secret.py
. Add in appropriate variables. Make sure to change the SECRET_KEY
field.
Add all required python packages and libraries to the requirements.txt
file. Use pip freeze > requirements.txt
.
Create the database.
First, install PostgreSQL by going to https://www.postgresql.org/download/.
Once PostgreSQL is installed, create a new database. You can do this by running psql
. This will open up a new shell to access the database. Next, create the database by running CREATE DATABASE DATABASE_NAME;
, replacing DATABASE_NAME
with your database name. Exit the shell by typing \q
.
Change the DB_URL value in your secret.py
file to use the following format: postgresql://localhost/DATABASE_NAME
.
When you are using a cloud based database (such as Google Cloud or AWS), use the following connection string: postgresql://USERNAME:PASSWORD@IP_ADDRESS/DATABASE_NAME
.
Add necessary code to your project.
All CSS files should be added to the static/css
folder. All JavaScript file should be added to the static/js
folder. All images should be added to the static/img
folder.
As you add code to the static/css
, static/js
and static/img
folders, you can remove the .gitignore
files in these folders.
All HTML files should be added to the templates
folder.
All views should be added to the app.py
file.
All models should be added to the models.py
file.
Run the development Flask Server by typing ./run.sh dev
. A server will start running and will be up at http://localhost:5000/.
Run the production Flask server by typing ./run.sh prod
. By default, the script will use gunicorn
to start the server with four workers and will be hosted on port 5000.
You should not share your secret.py
file with anyone.
Do not change the manage.py
file.
You should not commit your database file to GitHub.
The Procfile
is necessary if you are deploying to Heroku.
Do not change the database.py
file.
In order to get the database fully functional, run ./manage.py db init
to get the database running.
Every time you modify your models, run the following two commands in the following order:
./manage.py db migrate
./manage.py db upgrade
In order to get access to the shell, run ./manage.py shell
. This will open a shell without any imports.
In order to modify database entries (rows), once the shell opens run the following lines:
from app import db
from models import _
where the _ should be replaced by all of the models you wish to import.
Install the Heroku CLI.
Run the following command to login to Heroku: heroku login
.
Setup the git repo by running git init
.
Run the following command to create a new app: heroku create APP_NAME
.
Go to the Heroku Dashboard and click "Configure Add Ons". Then click "Find More Add-ons". Search for "Heroku Postgres" and click on it. Then click install. This will configure the database to the Heroku app.
Go to the settings tab and click "Reveal Config Vars". Add all of the variables that are listed in the secret.py
file.
Run git push heroku master
to push your code base to Heroku.
Navigate to https://APP_NAME.herokuapp.com
.
If you need to re-deploy, run the following set of commands:
git add .
git commit -m "COMMIT MESSAGE"
git push heroku master