# Django + Postgres API

> A Django REST Framework API with token auth, the Django admin and a Postgres database.

A Django 5.2 REST API with a notes resource, token auth for writes and the Django admin, on a managed Postgres database. Click Deploy and Naijacloud builds it from the public repo, creates the Postgres database and connects it, runs the migrations and gives you a live HTTPS address. No GitHub connection needed.

- Use case: API
- Stack: Django, Postgres
- Code: https://github.com/naijacloud/template-django-postgres-api (branch `main`)
- Deploy: https://naijacloud.com/new?template=django-postgres-api&ref=template-django-postgres-api
- Free tier: fits (1 app and 1 database per workspace)
- Last verified on Naijacloud: 9 Oct 2026
- Page: https://naijacloud.com/templates/django-postgres-api

## What's inside

- Django 5.2 and Django REST Framework, with a notes resource at /api/notes/
- Token auth for writes (reads are public), and the Django admin at /admin/
- Postgres through DATABASE_URL, static files through WhiteNoise, served by gunicorn
- Migrations and collectstatic run before gunicorn starts, on every deploy

## What you get after deploying

- A live address at https://django-postgres-api.naijacloud.app with HTTPS
- A Postgres database, with DATABASE_URL already set on the service
- Build and runtime logs, metrics and redeploys from the dashboard

## Environment variables

| Name | What it is for | Default |
| --- | --- | --- |
| `DATABASE_URL` | Postgres connection | set by Naijacloud |
| `DJANGO_SECRET_KEY` | Signs sessions and tokens | generated on deploy |
| `DJANGO_ALLOWED_HOSTS` | Hosts Django will answer | `.naijacloud.app,localhost,127.0.0.1` |
| `DJANGO_DEBUG` | Debug pages | `False` |

## Example request

```bash
curl -s https://django-postgres-api.naijacloud.app/api/notes/ | jq
```

```
{
  "count": 2,
  "next": null,
  "previous": null,
  "results": [
    { "id": 2, "title": "Deployed on Naijacloud", "body": "", "created": "2026-10-07T03:21:38.453788Z" },
    { "id": 1, "title": "First note", "body": "", "created": "2026-10-07T03:21:38.399505Z" }
  ]
}
```

## Run it locally

```bash
git clone https://github.com/naijacloud/template-django-postgres-api
cd template-django-postgres-api
python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
export DJANGO_DEBUG=True
python manage.py migrate
python manage.py runserver
```

Learn how it works: [Connecting to a database](https://naijacloud.com/docs/databases/connecting)

All templates: https://naijacloud.com/templates
