Skip to main content

shadcn/ui for Django

Project description

shadcn_django

Beautifully designed components that you can copy and paste into your apps, based on shadcn/ui.

This is an unofficial Django port of shadcn/ui. This project is not affiliated with shadcn.

Components are built with Tailwind CSS and Alpine.js and are HTMX-compatible, making them highly customizable and interactive.

shadcn_django provides a CLI tool that allows you to initialize and add shadcn-style components to your Django templates.

Docs: https://shadcn-django.com

Features

  • 🧩 Add components individually as needed
  • 🎨 Based on Tailwind CSS for beautiful, responsive styling
  • 🚀 Easy initialization of shadcn component architecture in Django projects
  • ⚙️ Uses Alpine.js for interactive functionality
  • 🛠️ Simple CLI commands for easy distribution
  • 📦 Automatically installs component dependencies

An Example of a component (Toast with an action button)

<div class="p-5" x-data>
  <c-toast.trigger variant="outline" toast_target="toast-success">
    Show Success Toast
  </c-toast.trigger>
</div>

<c-toast id="toast-success">
  <c-toast.content
    type="default"
    title="Success"
    description="This is a success message"
  >
    <c-button>Share</c-button>
  </c-toast.content>
</c-toast>

Toast

Installation

This is not a component library that you install. It is how you build your component library.

Use the CLI to initialize and add components without the need for installing it in your Django project.

uvx shadcn_django@latest --help

or, if you use pipx:

pipx run shadcn_django@latest --help

Getting Started

0. Add django-cotton to your Django project

shadcn_django uses django-cotton to manage the component architecture, because of it's elegant html like syntax. It is also interoperable with django templates, so you won't have to switch over your entire project.

See django-cotton installtion instructions.

1. Initialize shadcn-django in your project

uvx shadcn_django init

This will:

  • Create a templates/cotton directory for your components
  • Add the necessary Tailwind configuration files
  • Set up the CSS variables for shadcn's design system

2. Set up Tailwind CSS

Make sure you have Tailwind CSS and Alpine.js installed:

You can use npm or yarn to install tailwindcss:

npm install -D tailwindcss tailwindcss-animate

or, you can also use django-tailwind-cli if you don't want to use node.

See alpinejs docs for installation instructions: https://alpinejs.dev/installation

Add the CSS and Alpine.js to your base template <head> tag:

<!-- Tailwind CSS output file -->
<link rel="stylesheet" href="{% static 'css/output.css' %}" />

<!-- Alpine.js tag - directly from CDN (not recommended for production) -->
<script defer src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>

Run Tailwind to generate your CSS:

npx @tailwindcss/cli -i input.css -o static/css/output.css --watch

3. Add components

List available components:

uvx shadcn_django list

Add a component:

uvx shadcn_django add button

This will add the button component and any of its dependencies to your templates/cotton directory.

Using Components in Django Templates

After adding components, you can use them in your Django templates:

<div>
  <c-button variant="outline">Cancel</c-button>
  <c-button variant="default">Submit</c-button>
</div>

Customization

When you use the CLI to add components, they are copied into your project folder. You own the components and can customize them as you see fit.

All components use Tailwind CSS classes and can also be customized by passing additional classes:

<c-button variant="default" class="w-full mt-4" />

Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

Prior Art

License

MIT

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

shadcn_django-0.19.0.tar.gz (56.1 kB view details)

Uploaded Source

Built Distribution

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

shadcn_django-0.19.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file shadcn_django-0.19.0.tar.gz.

File metadata

  • Download URL: shadcn_django-0.19.0.tar.gz
  • Upload date:
  • Size: 56.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.2

File hashes

Hashes for shadcn_django-0.19.0.tar.gz
Algorithm Hash digest
SHA256 dcb7a6ce60ac8aed3b97397d45cac72b015cf1f25091feac15e0b8ec7fe28aae
MD5 5566b7101e6ef70761a152d534a05afe
BLAKE2b-256 f817bce457f3bfc28d72cdb0693d2d6374b03a2c0b7b25b9cc133f2913d5ebc7

See more details on using hashes here.

File details

Details for the file shadcn_django-0.19.0-py3-none-any.whl.

File metadata

File hashes

Hashes for shadcn_django-0.19.0-py3-none-any.whl
Algorithm Hash digest
SHA256 83c4d1ffe7322d483b290c48c59be20122e34bf61937c8ad2f0530c8f3befeb7
MD5 6976c1650a7064d2ff6707bad452e694
BLAKE2b-256 32324c87400d1129c4eff24dd1f2a9aed8985026a35012aeb66f3111aa720383

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