Skip to main content

A reusable Django bootstrap kit with UUID base models, a custom user model, and authentication views.

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_base_kit-0.2.0.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_base_kit-0.2.0-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

Details for the file django_base_kit-0.2.0.tar.gz.

File metadata

  • Download URL: django_base_kit-0.2.0.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for django_base_kit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 260200b2bafcc6789d58342eb24515a84c23ec20ef35a2ee53e9d14fb34faff8
MD5 9e7eed74a59090cd1bb9a7f118ae6dc8
BLAKE2b-256 f274bfbfa02f833e2758c8a9ee2dc22b6114e34a8149128b3037d7b3a4f9af06

See more details on using hashes here.

File details

Details for the file django_base_kit-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for django_base_kit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 15911d64e8d0e0f38c97fbd553f3326e46bf88496c5d96e33ee81b5ae193f7bb
MD5 dcf7843db9c65f4cf1e99a9ed3b78b91
BLAKE2b-256 c54fe186872afb8064431617e09ea94d2829e16f9fead19b6ccd90ac6f327a14

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page