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. However, it does not provide a way to customize the Tailwind configuration through Django settings. You're expected to customize the Tailwind configuration by editing the tailwind.input.css file in the dj_tailwind_output app. The user is responsible for any advanced configuration.

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: light --default;
}
@plugin "daisyui/theme" {
  name: light;
  font-family:
    Noto 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 Tailwind project.

Alternatives

  • [https://github.com/timonweb/django-tailwind] - similar project but it hasn't been updated in a while. This project is fairly similar.
  • [https://github.com/django-commons/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.

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.0.1.tar.gz (6.5 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.0.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for dj_tailwind-0.0.1.tar.gz
Algorithm Hash digest
SHA256 ccb73407b8c774e11055c84352605335e4cb307fbed43508880dbcbdff15c498
MD5 b55a7b4f96b329b1ef964fe20a533cc4
BLAKE2b-256 fc00029db950d19a2be195247c3f59b68886768e9df3c379cbb6d40e2ce49be2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_tailwind-0.0.1.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.0.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for dj_tailwind-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1d59e33502c490c78eef377a6fc6f74be17a05094c1dadeb5aa948acad712ef3
MD5 35f414cf6275c404c818537ed1abf378
BLAKE2b-256 1aba02d6e0d6adcce1224b6595280e5d06c5cd218841b207c382eb2b1d158060

See more details on using hashes here.

Provenance

The following attestation bundles were made for dj_tailwind-0.0.1-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