Lab 5 Starter Code
Starter code for Lab 5
To begin using this app you can do the following:
- Clone the repository to your local machine.
- Create a Python virtual environment e.g.
python -m venv venv
(You may need to usepython3
instead) - Enter the virtual environment using
source venv/bin/activate
(or.\venv\Scripts\activate
on Windows) - Install the dependencies using Pip. e.g.
pip install -r requirements.txt
. Note: Ensure you have PostgreSQL already installed and a database created. - Edit the
app/__init__.py
file and enter your database credentials and database name. - Run the migrations by typing
python manage.py db upgrade
- Start the development server using
python run.py
.
Separate Config file
I have included a separate config file app/config.py
that can be used for setting up
configuration for different environments e.g. Development and Production
Using this separate config file will also require you to set environment variables on your local computer or server at the command line. For example on Linux or MacOS:
export SECRET_KEY="my-super-secret-key"
export DATABASE_URL="postgresql://yourusername:yourpassword@localhost/databasename"
Or on Windows:
set SECRET_KEY="my-super-secret-key"
set DATABASE_URL="postgresql://yourusername:yourpassword@localhost/databasename"
If using PowerShell on Windows try the following:
$env:SECRET_KEY="YourRandomSecretKey"
$env:DATABASE_URL="postgresql://yourusername:yourpassword@localhost/databasename"
And on Heroku:
heroku config:set SECRET_KEY="my-super-secret-key"
heroku config:set DATABASE_URL="postgresql://yourusername:yourpassword@localhost/databasename"