Django 4 form rendering using Tailwind without Node or crispy

submited by
Style Pass
2022-10-01 04:00:29

Since Django 4, form rendering with Tailwind can be used to render beautiful forms without using Node or any other packages like django-crispy-forms. All you need is the Tailwind CLI binary and django-widget-tweaks.

The pytailwindcss package bundles the Tailwind CLI as a self-contained binary: not need to install Node! The downside is, that it’s not possible to use any Tailwind plugins except for the built-in ones like @tailwindcss/forms.

Use django-widget-tweaks to add custom Tailwind classes to the input elements. Implement your own form rendering template form_snipper.html.

Tailwind is great with components. Django templates are not great with components. It’s a good idea to define custom classes for highly re-usable elements like buttons and links. Define them in static/css/project.css.

Note that if you are using Tailwind with a framework like React, you should not define your custom CSS classes but instead heavily break down your UI into components.

Leave a Comment