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.3.tar.gz (9.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.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: django_tailwind_v4-0.2.3.tar.gz
  • Upload date:
  • Size: 9.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.3.tar.gz
Algorithm Hash digest
SHA256 1e33d0e3e323787042bffa8b6a03589479f226f1753f52d7ee4a606ccb9812a1
MD5 20f5555aefcbb894789958bc1d05cede
BLAKE2b-256 07b27efdfab2cc1dddcc5812526eef1c95db9a98a6a30ef683374d17cf20c265

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_tailwind_v4-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 82745e9a3ab88daed16c1df1cf75ff7d7c32595f2681b15c40455887fdb00b67
MD5 d517d12c8bcc52cffcbc5a3aea829b89
BLAKE2b-256 e979e6dcf257d27fed3731136dac2f305f046221bc575a55c40e253aef75ca9d

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