Installation
Setting up Preline UI in a Django project using Tailwind CSS.
This guide assumes you already have a Django project with django-tailwind configured. If you haven't set up django-tailwind yet, check out the django-tailwind documentation first.
Integrate Preline UI components with your existing Django + django-tailwind project. This guide focuses on adding Preline UI to an already configured Django project.
Install preline via npm or yarn in your Django project directory.
npm install preline
Please note, Preline UI uses Tailwind CSS Forms plugin in all form components. Don't forget to install it, if you haven't done so already: npm install -D @tailwindcss/forms
Add Preline UI CSS variants and forms plugin to your theme/static_src/src/styles.css file.
@import "tailwindcss";
/* Preline UI */
@import "../../../node_modules/preline/variants.css";
/* Plugins */
@plugin "@tailwindcss/forms";
/* Preline Themes */
@import "./themes/theme.css";
@source "../../../**/*.{html,py,js}";
Check out the Theme docs to learn more about Preline Themes.
Add static files configuration to Django settings and copy Preline JavaScript to your static directory.
STATICFILES_DIRS = [
BASE_DIR / "static",
]
mkdir -p static/js
cp node_modules/preline/dist/preline.js static/js/
Include Preline JavaScript and initialization script in your Django base template.
Please note, Preline UI comes with some opinionated styles that are applied to components by default. If you want these styles in your project, you may include them into your CSS file. These styles used to come by default in Tailwind v3, so we decided to keep them in Preline UI.
/* Adds pointer cursor to buttons */
@layer base {
button:not(:disabled),
[role="button"]:not(:disabled) {
cursor: pointer;
}
}
/* Defaults hover styles on all devices */
@custom-variant hover (&:hover);