Skip to main content

A simple Django app to integrate Tailwind CSS v4.

Project description

Django Tailwind CSS v4

PyPI version License: MIT

A simple, beginner-friendly Django app to integrate Tailwind CSS v4 into your project.

This package automates the setup process by providing management commands to initialize your project with the necessary Tailwind configuration and install its dependencies, without requiring complex bundlers like Webpack or Vite.


Key Features

  • Simple Setup: A single command to get you started.
  • Automated Dependency Installation: Automatically creates a package.json and runs npm install.
  • Django Integration: Works seamlessly with manage.py commands.
  • Official CLI: Uses the official @tailwindcss/cli for fast and reliable builds.
  • Development Ready: Includes a --watch mode for automatic rebuilding.
  • Production Ready: Supports CSS minification with a --minify flag.

Requirements

  • Python 3.8+
  • Django 4.2+
  • Node.js and npm

Installation

  1. Install the package from PyPI:

    pip install django-tailwind-v4
    
  2. Add it to your INSTALLED_APPS in settings.py:

    # settings.py
    INSTALLED_APPS = [
        # ... other apps
        'django_tailwind_v4',
    ]
    

Usage

1. Initialize Your Project

Run the tailwind_init command. This single command handles the entire setup process for you.

python manage.py tailwind_init

This will:

  • Create a package.json with the required Tailwind dependencies.
  • Create a tailwind.config.js file pre-configured for Django templates.
  • Create a static/src/input.css file with the correct v4 @import directive.
  • Automatically run npm install to download the Tailwind CLI.

2. Build Your CSS

Run the tailwind_build command to compile your CSS. For development, it's highly recommended to use the --watch flag in a separate terminal.

# For development (watches for changes and rebuilds automatically)
python manage.py tailwind_build --watch

# For a single production build (minified)
python manage.py tailwind_build --minify

### 3. Include the CSS in Your Template

Finally, link the compiled stylesheet in your base HTML template.

{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>My Awesome Site</title>
    <link href="{% static 'dist/output.css' %}" rel="stylesheet">
</head>
<body>
    <h1 class="text-3xl font-bold text-blue-600">
        Hello, Tailwind!
    </h1>
</body>
</html>

Configuration

While the package works out of the box, you have full control to customize its behavior.

Customizing Paths

You can change the default input and output CSS paths by adding the following variables to your settings.py file. This is useful if you are integrating with an existing theme structure.

# settings.py

# Path to your source CSS file (default is 'static/src/input.css')
TAILWIND_INPUT_CSS = 'themes/mytheme/css/styles.css'

# Path where the compiled CSS will be saved (default is 'static/dist/output.css')
TAILWIND_OUTPUT_CSS = 'themes/mytheme/static/css/styles.css'

Customizing Tailwind CSS

The tailwind.config.js file created by the init command is a standard Tailwind configuration file. You can edit it to customize your design system.

For example, to add custom colors:

// tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    './**/templates/**/*.html',
  ],
  theme: {
    extend: {
      colors: {
        'brand-blue': '#1992d4',
      },
    },
  },
  plugins: [],
}

You can also install and add Tailwind plugins. For example, to add the official forms plugin:

  1. Install the plugin via npm:
    npm install -D @tailwindcss/forms
    
  2. Add it to your tailwind.config.js:
    // tailwind.config.js
    module.exports = {
      // ...
      plugins: [
        require('@tailwindcss/forms'),
      ],
    }
    

License

This project is licensed under the MIT License. See the LICENSE file for details.

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_tailwind_v4-0.2.1.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

django_tailwind_v4-0.2.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file django_tailwind_v4-0.2.1.tar.gz.

File metadata

  • Download URL: django_tailwind_v4-0.2.1.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for django_tailwind_v4-0.2.1.tar.gz
Algorithm Hash digest
SHA256 95016f1870fdc8a67f4cb306bec3a66e1337d5221c7aec96519dfaa2d984e274
MD5 8b0bc0103c8eda7a41ec3d5912855b97
BLAKE2b-256 0d0f2b910d30c0b48926874cf83aa7b63be677b2b66412e4764a43ebb5f67aa0

See more details on using hashes here.

File details

Details for the file django_tailwind_v4-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_tailwind_v4-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 08edfa115e2748f28aee2e5abff91b5f67bc381bc31f0a6fa739bd8b71c48982
MD5 3b78c5de307b54e4a93c295a5f1264da
BLAKE2b-256 4d073a6661a0ee1573f6da15cfb9d8fff49caf68091438758bb737eb4215f41e

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