Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/laaraujo/django-api-template

Django API template for my projects
https://github.com/laaraujo/django-api-template

auth boilerplate coverage django django-rest-framework docker makefile postgresql pre-commit pytest template

Last synced: 13 days ago
JSON representation

Django API template for my projects

Awesome Lists containing this project

README

        

[![tests](https://github.com/laaraujo/django-api-template/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/laaraujo/django-api-template/actions/workflows/tests.yml)
[![codecov](https://codecov.io/gh/laaraujo/django-api-template/graph/badge.svg?token=6187LG7Y30)](https://codecov.io/gh/laaraujo/django-api-template)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

# Django API Template

Opinionated template repo to kickstart Back-end/API projects with Django Rest Framework.

## Features

- [Makefile](./Makefile) with common shorcuts for local development commands
- Authentication ([Djoser](https://djoser.readthedocs.io/))
- Registration
- Login
- Email validation
- Password reset (w/ email)
- Password reset confirmation
- Static file serving ([Whitenoise](https://whitenoise.readthedocs.io/))
- [Dockerfile](./Dockerfile)
- [Docker compose for local development](./compose.yml)
- [PostgreSQL](https://www.postgresql.org/)
- Auto Swagger Docs ([DRF Spectacular](https://drf-spectacular.readthedocs.io/))
- [Custom user model](./src/users/models.py) (email, password and name)
- Email via SMTP
- Pre-commit hooks ([Ruff](https://docs.astral.sh/ruff/) and [OTB Pre-commit hooks](https://github.com/pre-commit/pre-commit-hooks))
- Automated testing ([Pytest](https://docs.pytest.org/))
- [Modal bakery](https://model-bakery.readthedocs.io/)
- Test run parallelization with (pytest-xdist)[https://pytest-xdist.readthedocs.io/]
- [Faker](https://faker.readthedocs.io/)
- [Coverage](https://pytest-cov.readthedocs.io/)

## Local setup

```sh
git clone git@github.com:laaraujo/django-api-template.git # clone this repo
cd django-api-template # cd into repository directory
python -m venv .venv # create virtual environment
source .venv/bin/activate # activate virtual environment
pip install -r requirements.txt # install dependencies
pre-commit install # initialize pre-commit hooks
cp .env.example .env # create .env file
make build # build containers
make run # run your containers locally
```

## Make commands

```
build .................... : Build local containers
run ...................... : Run local containers
stop ..................... : Stop local containers
down ..................... : Stop and delete local container
makemigrations ........... : Django makemigrations command
migrate .................. : Django migrate command
createsuperuser .......... : Django createsuperuser command
shell .................... : Django shell command
sh ....................... : SSH into local API container
linter ................... : Run Ruff linter against all files in this repo
```

## Documentation

Swagger docs are available in the `/docs/` endpoint (http://localhost:8000/docs/).

:warning: You'll get a `403 Forbidden` response by default unless you are already logged in with an `admin` account (http://localhost:8000/admin/).
If you want to change this behaviour you can modify the required permissions in [./src/app/urls.py](./src/app/urls.py)