Skip to main content

django-base-kit

A bootstrap library for Django projects with:

  • an abstract BaseModel using UUID v4 as the primary key
  • a custom User model (AbstractUser + BaseModel)
  • ready-to-use authentication views and templates:
    • login
    • logout
    • change password
    • password reset ("forgot password")

Installation

pip install django-base-kit

For local development from a clone:

pip install -e ".[dev]"

What this package provides

1) Reusable BaseModel

File: django_base_kit.models.BaseModel

Included fields:

  • id (UUIDField, primary_key=True, default=uuid.uuid4)
  • created_at
  • updated_at
  • active
  • changelog

Example usage in any app:

from django.db import models
from django_base_kit.models import BaseModel


class Product(BaseModel):
    name = models.CharField(max_length=120)
    price = models.DecimalField(max_digits=10, decimal_places=2)

    def __str__(self):
        return self.name

2) Custom User model

File: django_base_kit.models.User

  • inherits from BaseModel
  • inherits from AbstractUser
  • unique email
  • model app label: base_kit

So in settings.py, use:

AUTH_USER_MODEL = "base_kit.User"

3) Auth stack (views + forms + templates)

The package already includes forms, views, and templates for:

  • login
  • logout
  • change password
  • password reset (form, done, confirm, complete)

Routes are exposed through django_base_kit.urls.user_urlpatterns.

Consumer project setup

The repository also contains a small core/ Django project used as a local example for development. It is not included in the published package; only the django_base_kit reusable app is packaged.

1) settings.py

Add/update:

INSTALLED_APPS = [
    # django apps...
    "auditlog",
    "widget_tweaks",
    "django_base_kit",
]

AUTH_USER_MODEL = "base_kit.User"

# Email sender used by password reset views
# The view reads FROM_MAIL and falls back to DEFAULT_FROM_EMAIL
FROM_MAIL = "no-reply@example.com"
DEFAULT_FROM_EMAIL = FROM_MAIL

# Local development (prints emails in the console)
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"

# Recommended so Django can find package templates
TEMPLATES = [
    {
        # ...
        "APP_DIRS": True,
    },
]

# Optional: override package templates and success_urls per view
BASE_KIT = {
    # success_urls configuration
    "signup_success_url": "/",
    "login_success_url": "/",
    "logout_success_url": "/accounts/login/",

    # templates configuration
    "signup_template": "my_auth/signup.html",
    "login_template": "my_auth/login.html",
    "change_password_template": "my_auth/change_password.html",
    "reset_password_template": "my_auth/reset_password_form.html",
    "reset_password_done_template": "my_auth/reset_password_done.html",
    "reset_password_confirm_template": "my_auth/reset_password_confirm.html",
    "reset_password_complete_template": "my_auth/reset_password_complete.html",
    "reset_password_email_template": "my_auth/reset_password_email.html",
}

If a key is omitted, the default template shipped with django_base_kit is used.

2) Auditlog integration

To enable audit logs in consumer projects:

  1. Make sure auditlog is installed and enabled in INSTALLED_APPS.

  2. Add middleware in settings.py:

MIDDLEWARE = [
    # ...
    "auditlog.middleware.AuditlogMiddleware",
]
  1. In your model files, import and register the model:
from auditlog.registry import auditlog


class MyModel(BaseModel):
    # your fields...
    pass


auditlog.register(MyModel)

3) Project urls.py

from django.contrib import admin
from django.urls import path
from django_base_kit.urls import user_urlpatterns

urlpatterns = [
    path("admin/", admin.site.urls),
] + user_urlpatterns

4) Base template requirement (base.html)

The package templates use:

{% extends "base.html" %}

So your project must provide a base.html template.

Minimal example:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>{% block title %}My Project{% endblock %}</title>
</head>
<body>
  {% block content %}{% endblock %}
</body>
</html>

Recommended location:

  • templates/base.html in your Django project (with your TEMPLATES setting pointing to this directory), or
  • any template directory already configured in your project.

5) Migrations

In a new project:

python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser

Available routes

  • /accounts/signup/
  • /accounts/login/
  • /accounts/logout/
  • /change_password/
  • /reset_password/
  • /reset_password/done
  • /reset_password/confirm/<uidb64>/<token>/
  • /reset_password/complete/

Important notes

  • Set AUTH_USER_MODEL = "base_kit.User" before your first migration.
  • If your project already migrated with auth.User, you will need a user migration plan.
  • For password reset in production, configure SMTP (EMAIL_HOST, EMAIL_PORT, EMAIL_HOST_USER, EMAIL_HOST_PASSWORD, EMAIL_USE_TLS/SSL).

License

MIT

Metadata

Release files for django-base-kit 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-base-kit 0.2.0
File Size Uploaded
django_base_kit-0.2.0.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-base-kit 0.2.0
File Interpreter ABI Platform
django_base_kit-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 31.1 kB

Release files / django_base_kit-0.2.0.tar.gz

Download URL django_base_kit-0.2.0.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
260200b2bafcc6789d58342eb24515a84c23ec20ef35a2ee53e9d14fb34faff8
BLAKE2b-256 checksum
How to use checksums
f274bfbfa02f833e2758c8a9ee2dc22b6114e34a8149128b3037d7b3a4f9af06
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / django_base_kit-0.2.0-py3-none-any.whl

Download URL django_base_kit-0.2.0-py3-none-any.whl
Size 17.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
15911d64e8d0e0f38c97fbd553f3326e46bf88496c5d96e33ee81b5ae193f7bb
BLAKE2b-256 checksum
How to use checksums
c54fe186872afb8064431617e09ea94d2829e16f9fead19b6ccd90ac6f327a14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.3

1 release file

0.0.2

1 release file

0.0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page