This application is a simple python API using the Django framework and Neon Postgres database. It returns a list of authors and books written by them. We illustrate how to generate and run schema change migrations.
To build this project from scratch, check out the guide in Neon's documentation.
You will need the following:
- A Neon account and a project
- Python 3.8 or higher
- Clone this repository:
git clone https://github.com/neondatabase/guide-neon-django
- Navigate to the project directory and create a new virtual environment:
cd guide-neon-django
python -m venv myenv
- Activate the virtual environment and install the project dependencies:
source myenv/bin/activate
pip install -r requirements.txt
- Create a
.env
file in the root of the project and add the following environment variable with your Neon database URL:
DATABASE_URL=
- Run the Django migrations:
python manage.py migrate
- Start the Django development server:
python manage.py runserver
- Visit
http://localhost:8000
in your browser to see the list of authors and books. Or use curl to access the api from the terminal.
# Get the list of authors
curl http://localhost:8000/catalog/authors
# Get books by author with id 1
curl http://localhost:8000/catalog/books/1