From d7412496441d28753f137847fbaff4e37f49fe4b Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Mon, 20 Apr 2026 14:44:10 +0545 Subject: [PATCH] feat(templates): add Tailwind and HTMX integration and fix static/media URLs Introduce Tailwind and HTMX support with conditional placeholders and correct static/media URL prefixes. - New Features - Add django_tailwind_cli and django_htmx when enabled - Add HtmxMiddleware to middleware stack - Pin Tailwind CLI version and set distribution CSS path in production - Configure Tailwind theme and daisyui settings - Enhancements - Prefix STATIC_URL and MEDIA_URL with '/' for proper URL handling - Update requirements templates with new optional dependencies - Expand pyproject.toml metadata and dependency groups - Bug Fixes - Fix missing leading slash in STATIC_URL and MEDIA_URL - Pin Tailwind CLI version to avoid unexpected upgrades --- .../templates/config/settings/base.py-tpl | 44 ++++++++++++++++++- .../config/settings/production.py-tpl | 7 +++ src/djinit/templates/project/requirements-tpl | 2 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/djinit/templates/config/settings/base.py-tpl b/src/djinit/templates/config/settings/base.py-tpl index 1e0c491..15a5da0 100644 --- a/src/djinit/templates/config/settings/base.py-tpl +++ b/src/djinit/templates/config/settings/base.py-tpl @@ -26,6 +26,8 @@ THIRD_PARTY_APPS = [ "rest_framework_simplejwt.token_blacklist", "corsheaders", "drf_spectacular", + "django_tailwind_cli", # @IF use_tailwind + "django_htmx", # @IF use_htmx ] USER_DEFINED_APPS = [ @@ -56,6 +58,7 @@ MIDDLEWARE = [ "django.contrib.auth.middleware.AuthenticationMiddleware", "django.contrib.messages.middleware.MessageMiddleware", "django.middleware.clickjacking.XFrameOptionsMiddleware", + "django_htmx.middleware.HtmxMiddleware", # @IF use_htmx ] ROOT_URLCONF = "[[ project_name ]].urls" @@ -106,10 +109,10 @@ USE_I18N = True USE_TZ = True # Static files and media files -STATIC_URL = "static/" +STATIC_URL = "/static/" STATIC_ROOT = BASE_DIR / "staticfiles" -MEDIA_URL = "media/" +MEDIA_URL = "/media/" MEDIA_ROOT = BASE_DIR / "media" STORAGES = { @@ -185,3 +188,40 @@ CORS_PREFLIGHT_MAX_AGE = 86400 # 24 hours SECURE_BROWSER_XSS_FILTER = True SECURE_CONTENT_TYPE_NOSNIFF = True X_FRAME_OPTIONS = "DENY" + +# @IF use_tailwind +# for tailwind +STATICFILES_DIRS = [BASE_DIR / "static/"] +TAILWIND_CLI_VERSION = "2.7.8" +TAILWIND_CLI_USE_DAISY_UI = True +TAILWIND_CLI_CONFIG = { + "theme": { + "extend": { + "colors": { + "primary": "#DC2626", + "secondary": "#EF4444", + "accent": "#FCFECC", + } + } + }, + "daisyui": { + "themes": [ + { + "light": { + "primary": "#DC2626", + "secondary": "#EF4444", + "accent": "#FCFECC", + "neutral": "#1a1a2e", + "base-100": "#ffffff", + "base-200": "#f8fafc", + "base-300": "#e2e8f0", + "info": "#0E4D80", + "success": "#16a34a", + "warning": "#f59e0b", + "error": "#DC2626", + } + } + ] + }, +} +# @ENDIF diff --git a/src/djinit/templates/config/settings/production.py-tpl b/src/djinit/templates/config/settings/production.py-tpl index 630fae0..c454e0f 100644 --- a/src/djinit/templates/config/settings/production.py-tpl +++ b/src/djinit/templates/config/settings/production.py-tpl @@ -65,3 +65,10 @@ CSRF_COOKIE_SECURE = True # Static files STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' + +# @IF use_tailwind +## Tailwind +TAILWIND_CLI_VERSION = "4.1.3" # Pin version +TAILWIND_CLI_AUTOMATIC_DOWNLOAD = False # Use pre-installed CLI +TAILWIND_CLI_DIST_CSS = "static/css/tailwind.min.css" +# @ENDIF diff --git a/src/djinit/templates/project/requirements-tpl b/src/djinit/templates/project/requirements-tpl index cb48ff9..bfefe12 100644 --- a/src/djinit/templates/project/requirements-tpl +++ b/src/djinit/templates/project/requirements-tpl @@ -10,6 +10,8 @@ djangorestframework_simplejwt drf-spectacular django-cors-headers whitenoise +django-tailwind-cli # @IF use_tailwind +django-htmx # @IF use_htmx # @IF database_type == 'mysql' mysqlclient # @ELSE