Backend Flask API template using Postgres
This README describes how to setup the environment and run the flask server
Based on the template found here https://github.com/spchuang/DoubleDibz-tutorial/tree/master/FINAL
This has been developed using python 3.6. You are recommended to use Anaconda or virtualenv to hold the dependencies to not pollute the system installs.
To install all packages and clean up the directory afterwards do
python setup.py install
python setup.py clean
This template uses environment variables to store the SECRET_KEY value, DATABASE_URL, and TEST_DATABASE_URL. So make sure you create a .env
file in the root directory and populate those values, you can see them being used in the app/config.py
file.
Install Postgres
This can be accomplished on mac using homebrew with the command
brew install postgres
Run postgres before doing the following commands either in the foreground or background To run in the foreground use the command on mac
postgres -D /usr/local/var/postgres
sudo su - postgres
psql
if the above command does not work then do
sudo -u username psql postgres
where username is your username
create role XXX with createdb login password 'XXX';
To create the development database and test database run the following
CREATE DATABASE XXX OWNER XXX;
CREATE DATABASE XXX OWNER XXX;
If you would like to keep postgres running in the background and restart it use the command
sudo service postgresql restart
To create the database tables you must run the following command in the root directory
python manage.py initdb
To run the application you must run the following command in the root directory
python manage.py run
To test the application you must run the following command in the root directory
nose2