If you would like to contribute to the Civic Tech Index project, please see the issues and project management board in the repository for the React app which uses this Django app as its API backend.
This project uses Django with Django REST Framework. If you are not already familiar with Django, we suggest you work through the Django tutorial and the Django REST Framework tutorial to get familiar with the tools this project uses. (Don't spend too long on these; just use them to get a feel for Django development.)
This project can be run using Docker OR installed directly on your machine.
This repository contains a Dockerfile for building a container for running our
Django project - in dev and in AWS via FARGATE. To use Docker for development,
you will want to use the project's docker-compose.yaml
to also create a
Postgres database container, a volume for persisting your data, and a network
that allows your web container to talk to your database container.
- Install Docker
- Clone this repository
- Copy
config/.env.example
toconfig/.env
- Build and configure your docker container by running the following command:
docker-compose up -d --build
- Our
docker-compose.yaml
creates a volume for persisting the database information so you should only have to run the migrations, load the data, and create a superuser the first time you create your containers.init/setup-db.sh
- Install PostgreSQL if you haven't already.
- Clone this repository
- Create and activate a virtual environment
- Install the packages
pip install -r requirements.txt
- Copy
config/.env.example
toconfig/.env
and edit to provide the database credentials your project will use. The contents of your .env file should provide the following information (though the values for user, host, db will depend on how you have configured your local Postgres database):POSTGRES_NAME='postgres' POSTGRES_PASSWORD='postgres' POSTGRES_USER='postgres' POSTGRES_HOST='localhost'
- Execute the following steps to load the environment variables from above and
set up your database. You should only need to do these steps the first time
you create a new database.
source config/.env python manage.py migrate python manage.py createsuperuser python manage.py loaddata init/organizations.json
- Start your web server in the foreground:
source config/.env python manage.py runserver
- Navigate to the Django Administration Page http://127.0.0.1:8888/admin/
- Login using superuser credentials
- This takes you to the Django admin interface for this project
If you are running this project using Docker, log into the docker container: docker exec -ti cti-web /bin/bash
From the root of the project, run the tests: pytest
To run tests and see the coverage report run: pytest --cov=civictechindexadmin