Skip to main content

A modern, role-based Django CMS registry with rich media previews

Project description

django-var-cms

A modern, highly customizable administrative Control Panel and CMS registry for Django projects. Built with premium glassmorphic aesthetics, role-based security, and rich media processing.

Created by Rahul Baberwal.


๐Ÿš€ Key Features

  • ๐ŸŽจ Modern Design System: Responsive glassmorphic layout, collapsible navigation sidebar with localStorage persistent state, and custom HSL accent color configurations.
  • ๐Ÿ”‘ Role & User Permissions: Manage fine-grained view, list, edit, add, and delete actions matching Django Groups or specific user accounts.
  • ๐Ÿ“ HTML Editor: Integrated Quill.js rich text editor out of the box.
  • โœ… Regex Field Validation: Easily enforce custom regular expression patterns both client-side and server-side.
  • ๐Ÿ–ผ๏ธ Media Previews & Image Cropper:
    • Modal-based previews for images, video, audio, and PDFs.
    • Built-in Image Cropper (rotate, flip, custom aspect ratio crops).
    • API endpoints for media conversion (JPEG, PNG, WebP, WAV, MP3, MP4).

โš™๏ธ Setup & Installation

1. Install Dependencies

Install django-var-cms along with required media dependencies:

# Using pip
pip install django-var-cms pillow whitenoise

# Using uv
uv add django-var-cms pillow whitenoise

2. Configure settings.py

Register "var_cms" in your Django INSTALLED_APPS and specify static/media paths:

# settings.py

INSTALLED_APPS = [
    # ... Django standard apps
    "var_cms",
    # "demo", (optional demo app)
]

# Media settings for handling file uploads/crops
MEDIA_URL = "/media/"
MEDIA_ROOT = BASE_DIR / "media"

# Static files settings
STATIC_URL = "/static/"
STATICFILES_DIRS = [BASE_DIR / "static"]
STATIC_ROOT = BASE_DIR / "staticfiles"

# Redirect paths for authentication
LOGIN_URL = "/var-cms/login/"
LOGIN_REDIRECT_URL = "/var-cms/"

3. Add URL Routing

Include the var_cms routes in your project's main urls.py:

urls.py

from django.urls import path, include from django.conf import settings from django.conf.urls.static import static

urlpatterns = [ # ... other paths path("var-cms/", include("var_cms.urls", namespace="var_cms")), ]

CRITICAL: Serve uploaded media files (images/files) during local development

if settings.DEBUG: urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)


---

## ๐Ÿงช Seeding the Demo App (Optional)

If you are developing or exploring features in the source repository:
1. Run migrations to initialize the database:
   ```bash
   python manage.py migrate
  1. Run the seed management command to generate default database models, pages, media, and test accounts:
    python manage.py seed_demo
    
  2. Start the server:
    python manage.py runserver
    
  3. Access the dashboard at http://127.0.0.1:8000/var-cms/.

Demo User Accounts

Username Password Role / Group Permissions
admin admin superuser Full unrestricted access
editor editor editor Add + Edit (Cannot delete)
author author author Add + Edit specific fields (Cannot delete)
viewer viewer viewer List + View records only
alice alice viewer Viewer permissions, with delete override

๐Ÿ› ๏ธ Registering Models (Example)

Create a file named var_cms_admin.py in any of your Django apps. It is automatically discovered on startup.

# myapp/var_cms_admin.py
from var_cms.registry import var_cms_site, VarCMSModelAdmin
from var_cms.permissions import RolePermission, UserPermission
from .models import Article

# Customize branding globally
var_cms_site.site_header = "My CMS"
var_cms_site.site_sub    = "Control Center"
var_cms_site.site_url    = "https://example.com"
var_cms_site.logo_url    = "/static/var_cms/var.png"  # Custom brand logo

class ArticleAdmin(VarCMSModelAdmin):
    list_display  = ["title", "category", "author", "status", "created_at"]
    list_filter   = ["status", "category"]
    search_fields = ["title", "body", "author"]
    readonly_fields = ["created_at", "updated_at", "view_count"]
    
    # Enable Quill.js Rich Text Editor on body field
    html_fields = ["body"]
    
    # Custom icon from Lucide
    icon = "file-text"
    
    # Regex validator: client-side + server-side validation
    regex_validators = {
        "slug": (r"^[a-z0-9-]+$", "Slug must consist of lowercase letters, numbers, and hyphens only.")
    }
    
    # Define role permissions
    permissions = [
        RolePermission("superuser", add=True,  list=True, view=True, edit=True,  delete=True),
        RolePermission("editor",    add=True,  list=True, view=True, edit=True,  delete=False),
        RolePermission("author",    add=True,  list=True, view=True, edit=True,  delete=False),
        RolePermission("viewer",    add=False, list=True, view=True, edit=False, delete=False),
        UserPermission("alice",     add=True,  list=True, view=True, edit=True,  delete=True),
    ]
    
    # Limit editable fields by user role
    role_editable_fields = {
        "superuser": "__all__",
        "editor":    ["title", "slug", "body", "status", "category"],
        "author":    ["title", "body", "status"],
        "*":         [],
    }

# Register the model on the custom site
var_cms_site.register(Article, ArticleAdmin)

๐ŸŽจ Layout Customizations

You can customize the accent color scheme using HSL values on the global var_cms_site registry:

# Custom accent color (Emerald green)
var_cms_site.accent_color = "142, 72%, 45%"

๐Ÿ“ URL Structure

/var-cms/                          โ†’ Admin Dashboard
/var-cms/{app}/{model}/            โ†’ Paginated List view
/var-cms/{app}/{model}/add/        โ†’ Object Creation Form
/var-cms/{app}/{model}/{pk}/       โ†’ Object Modification Form
/var-cms/{app}/{model}/{pk}/view/  โ†’ Read-only Details view
/var-cms/{app}/{model}/{pk}/delete/โ†’ Object Delete confirmation
/var-cms/api/media/crop/           โ†’ POST endpoint: crop image
/var-cms/api/media/convert/        โ†’ POST endpoint: convert media file type

๐Ÿ“– Detailed Integration & How To Use Guide

For detailed reference on branding customizations, optional two-factor authentication (OTP), and role-based permissions, see below:

๐ŸŽจ Branding & Customization Settings

You can customize the header, subtitle, favicon, and email verification options on the global registry singleton.

Inside your var_cms_admin.py or startup setup, modify the settings on the singleton instance var_cms_site:

from var_cms.registry import var_cms_site

# โ”€โ”€ Change Name & Subtitle โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
var_cms_site.site_header = "CMS"              # Default: "VAR CMS"
var_cms_site.site_sub    = "DASHBOARD"        # Default: "CONTROL PANEL"

# โ”€โ”€ Customize "View Site" Link โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
var_cms_site.site_url    = "https://myblog.com" # Default: "/"

# โ”€โ”€ Custom Image Logo & Favicon โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
var_cms_site.logo_url    = "/static/var_cms/var.png"  # Serves var.png as the brand logo & tab favicon

# โ”€โ”€ Optional OTP 2FA Verification โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
var_cms_site.enable_otp  = True               # Requires SMTP settings. Sends 6-digit OTP code to email.

๐Ÿ”‘ Authentication & Password Tools

1. Custom Glassmorphic Login

  • A premium, modern dark login interface is provided out-of-the-box at /var-cms/login/.

2. Optional OTP Verification (2FA)

  • When enable_otp = True, successful user logins redirect to an OTP verification view.
  • The system sends a 6-digit code to the user's email.
  • Development Tip: If SMTP parameters are not configured in settings.py, the code prints directly to your terminal console as [VAR CMS OTP]: ****** to prevent developers from getting locked out.

3. Forgot Password Request

  • Includes a "Forgot Password" link on the login screen. It prompts users to enter their email or username, generates a password reset OTP, and allows defining a new password securely.

4. Logged-in Password Reset

  • Users can change their password directly inside the dashboard. Click the User profile badge -> select Reset Password. It renders a custom password modification form embedded within the base CMS template.

๐Ÿ‘ฅ Credits & Authors

Created and maintained by Rahul Baberwal โ€” rahulbaberwal.com.

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_var_cms-1.0.6.tar.gz (747.4 kB view details)

Uploaded Source

Built Distribution

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

django_var_cms-1.0.6-py3-none-any.whl (759.5 kB view details)

Uploaded Python 3

File details

Details for the file django_var_cms-1.0.6.tar.gz.

File metadata

  • Download URL: django_var_cms-1.0.6.tar.gz
  • Upload date:
  • Size: 747.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for django_var_cms-1.0.6.tar.gz
Algorithm Hash digest
SHA256 5214b36902c17550f409edf1671cf1ec4f631157cb599d2ef61aa21b04f3641f
MD5 dd47942ecc2e0e4d89151bfe85dadc00
BLAKE2b-256 fea8b29001d5f84f79eae021a0488e2ef39fcbedd2d5b1fe3ce0d94ced7f2164

See more details on using hashes here.

File details

Details for the file django_var_cms-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: django_var_cms-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 759.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for django_var_cms-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7cc0f15fe5751fff6b722ba324768f0d2d63d45235656ee6e29d2f0d43d815f1
MD5 8683935951dd98b5a9482b7f16987b78
BLAKE2b-256 dafab431f53b96464944a06e1a0c8d27a1bbc2d88d8c477efaab125a16cbb207

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