Skip to main content

A Django project made to easier integrate Tailwind.

Project description

Dj-tailwind

Test Supported Python versions PyPI Version

Dj-tailwind is a Django app that allows you to quickly add Tailwind to your project. It's a simple way to get started with Tailwind CSS in Django. The setup is minimal, and you can start using Tailwind in your project in minutes.

Features:

  • Uses cookiecutter to initialize an empty Tailwind project.
  • Adds commands for building, updating and watching and Tailwind.
  • Provides template tags for including Tailwind CSS in your templates.
  • Provides settings to configure the initial Tailwind build.

Installation

Install dj-tailwind with pip:

pip install dj-tailwind`

Add the app and dependencies to installed Django applications:

INSTALLED_APPS = [
    ...
    "dj-tailwind",
    ...
]

Optional: set the Tailwind configuration in your settings file:

DJ_TAILWIND_APP_NAME = "tailwind" # The name of the app that will be created, defaults to `dj_tailwind_output`
DJ_TAILWIND_ENABLE_DAISYUI = True # Enable daisyUI

Run the init command to create the Tailwind project:

python manage.py dj_tailwind init

The preceding command generates a Django app called dj_tailwind_output which contains the Tailwind project. The folder is located in the root of your Django project.

Add the generated app to your installed apps:

INSTALLED_APPS = [
    ...
    "dj_tailwind_output",
    ...
]

Add the Tailwind CSS to your base template:

{% load tailwind_tags %}

<head>
{% dj_tailwind_css %}
</head>

Run the start command to start the Tailwind project in watch mode:

python manage.py dj_tailwind start

Customization

Dj-tailwind uses the default Tailwind configuration file and optionally adds the daisyUI plugin. To not introduce complexity and leave customization to end users, you're expected to customize the Tailwind configuration by editing the tailwind.input.css file in the dj_tailwind_output app. An example configuration file custom fonts and themes:

@import 'tailwindcss' source('../');
@plugin "@tailwindcss/typography";
@plugin "@tailwindcss/forms";
@plugin "@tailwindcss/aspect-ratio";

@plugin "daisyui" {
  themes: dark, light;
}

@plugin "daisyui/theme" {
  name: 'dark';
  prefersdark: true;
  --color-primary: oklch(70% 0.165 254.624);
  --color-primary-content: oklch(98% 0.001 106.423);
}

@plugin "daisyui/theme" {
  name: 'light';
  default: true;
  --color-primary: oklch(54% 0.245 262.881);
  --color-primary-content: oklch(98% 0.001 106.423);
}

@theme {
  --font-sans: Inter var;
}

Production Builds

To build the Tailwind project for production, run the build command:

./manage.py tailwind install
./manage.py tailwind build
./manage.py collectstatic --no-input

Commands

Dj-tailwind provides several commands to manage the Tailwind project:

  • ./manage.py dj_tailwind init - Initializes the Tailwind project.
  • ./manage.py dj_tailwind build - Builds the Tailwind project.
  • ./manage.py dj_tailwind start - Starts the Tailwind project in watch mode.
  • ./manage.py dj_tailwind update - Updates the NPM dependencies.

Alternatives

  • Django-tailwind - similar project but it hasn't been updated in a while. This project is fairly similar but this is up to date and more lightweight.
  • Django-tailwind-cli - uses the precompiled Tailwind command-line tool, no dependency on Node. However, custom theming seems more complex.

Migrating from Django-tailwind

If you're using the django-tailwind package, you can migrate to dj-tailwind by following these steps:

  1. Remove the theme app directory from your project and the django_tailwind app from your installed apps.
  2. If you've added custom Tailwind configuration, you can copy it to the new dj_tailwind_output app. Tailwind 4.0 doesn't support tailwind.config.js files, so you'll need to use the tailwind.input.css file instead.
  3. Dj-tailwind uses Tailwind 4.0, which has breaking changes. You'll need to update your templates to use the new Tailwind classes. Read more here.
  4. Follow the installation instructions to install dj-tailwind and initialize the Tailwind project.
  5. The commands are prefixed with dj_tailwind instead of tailwind.

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

dj_tailwind-0.2.0.tar.gz (67.4 kB view details)

Uploaded Source

Built Distribution

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

dj_tailwind-0.2.0-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dj_tailwind-0.2.0.tar.gz
  • Upload date:
  • Size: 67.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_tailwind-0.2.0.tar.gz
Algorithm Hash digest
SHA256 01893e959722f89edd6421128ab18d91b24553b8d4af341bd1a60b5d33a2eae4
MD5 2ce687c3319fe748739581b439efe4cf
BLAKE2b-256 45b9111df1db96aa1765317f793e551aabea51cb797789820c31a5897523162f

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_tailwind-0.2.0.tar.gz:

Publisher: ci-cd.yml on adinhodovic/dj-tailwind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: dj_tailwind-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dj_tailwind-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 24b45a8aa2412b165484a136a5cc1a10e83c91c5ce0bdb03de3219debde5e9d5
MD5 4d4ad76a5249186f5413041d4646474a
BLAKE2b-256 0d32921bd014605fd1e2eb6c0f4d365cf6bbad18ce346f1ea65b6292bef903b0

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_tailwind-0.2.0-py3-none-any.whl:

Publisher: ci-cd.yml on adinhodovic/dj-tailwind

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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