Skip to content

bpolack/drf-basic-auth

Repository files navigation

DRF Basic Auth

Django Rest API with auth

Built with Cookiecutter Django Ruff

License: MIT

Settings

Moved to settings.

Local Setup

Prerequisites

  • Python 3.13
  • uv
  • PostgreSQL running locally

1. Install dependencies

uv sync --locked

2. Create a local environment file

This project only reads values from .env when DJANGO_READ_DOT_ENV_FILE=True is set. Create a .env file in the repository root with at least the below. Or alternatively, configure the .zshrc file in your home directory to contain these values.

DJANGO_READ_DOT_ENV_FILE=True
DJANGO_SETTINGS_MODULE=config.settings.local
DJANGO_DEBUG=True
MARTINI_DATABASE_URL=postgres://postgres@127.0.0.1:5432/martini

MARTINI_DATABASE_URL is the database setting used by config/settings/base.py. If you want to use a different database name, change the value in .env to match.

Examples:

MARTINI_DATABASE_URL=postgres://postgres@127.0.0.1:5432/helloworld

3. Create the PostgreSQL database

Create a local Postgres database with the same name used in MARTINI_DATABASE_URL.

If you are using the default value from above:

createdb martini

If you changed the database name, create that database instead.

4. Run migrations

uv run python manage.py migrate

5. Create a superuser

uv run python manage.py createsuperuser

6. Start the development server

uv run python manage.py runserver

The app will be available at http://127.0.0.1:8000.

Allauth Headless API

This repo mounts django-allauth headless routes at /_allauth/. In allauth headless mode, the API paths are grouped by client type:

  • /_allauth/browser/v1/...
  • /_allauth/app/v1/...

Basic endpoints you will commonly use include:

  • /_allauth/{client}/v1/auth/session
  • /_allauth/{client}/v1/auth/login
  • /_allauth/{client}/v1/auth/signup
  • /_allauth/{client}/v1/auth/password/request
  • /_allauth/{client}/v1/auth/password/reset
  • /_allauth/{client}/v1/auth/email/verify
  • /_allauth/{client}/v1/auth/provider/*

{client} is typically either browser or app, depending on how your frontend authenticates.

For the complete and authoritative endpoint list, including request methods, schemas, MFA flows, provider-specific routes, and OpenAPI details, see the official allauth headless docs:

Basic Commands

Setting Up Your Users

  • To create a normal user account, just go to Sign Up and fill out the form. Once you submit it, you'll see a "Verify Your E-mail Address" page. Go to your console to see a simulated email verification message. Copy the link into your browser. Now the user's email should be verified and ready to go.

  • To create a superuser account, use this command:

    uv run python manage.py createsuperuser
    

For convenience, you can keep your normal user logged in on Chrome and your superuser logged in on Firefox (or similar), so that you can see how the site behaves for both kinds of users.

Type checks

Running type checks with mypy:

uv run mypy extra_dry_martini

Test coverage

To run the tests, check your test coverage, and generate an HTML coverage report:

uv run coverage run -m pytest
uv run coverage html
uv run open htmlcov/index.html

Running tests with pytest

uv run pytest

Live reloading and Sass CSS compilation

Moved to Live reloading and SASS compilation.

Celery

This app comes with Celery.

To run a celery worker:

cd extra_dry_martini
uv run celery -A config.celery_app worker -l info

Please note: For Celery's import magic to work, it is important where the celery commands are run. If you are in the same folder with manage.py, you should be right.

To run periodic tasks, you'll need to start the celery beat scheduler service. You can start it as a standalone process:

cd extra_dry_martini
uv run celery -A config.celery_app beat

or you can embed the beat service inside a worker with the -B option (not recommended for production use):

cd extra_dry_martini
uv run celery -A config.celery_app worker -B -l info

Deployment

The following details how to deploy this application.

About

Django Rest Framework with basic auth

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors