Skip to main content

Reusable UI components for your Django templates

Project description

Django UI Components

Reusable UI components for your Django templates

PyPI Build Status

Usage

  1. Create a component file, such as ./templates/components/button.html.
<button class="px-4 py-2 font-semibold rounded-lg shadow text-sm text-white
  {% if variant == 'danger' %}
    bg-red-500 hover:bg-red-400
  {% elif variant == 'success' %}
    bg-green-500 hover:bg-green-400
  {% else %}
    bg-blue-500 hover:bg-blue-400
  {%endif%}
">
  {{ text }}
</button>
  1. Load components at the top of your template and include the UI component by using the component template tag possibly with keyword arguments.
{% load static %}
{% load components %}

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Django UI Components</title>
    <link rel="stylesheet" href="{% static 'css/styles.css' %}">
    <link rel="icon" type="image/x-icon" href="{% static 'favicon.ico' %}">
  </head>

  <body class="bg-gray-50 flex items-center min-h-screen justify-center">
    {% component 'button.html' text="Delete" variant="danger" %}
    {% component 'button.html' text="Save" variant="success" %}
    {% component 'button.html' text="Ok" %}
  </body>
</html>
  1. This results in three button variations.
Example screenshot

Install

Install the package from pypi.

$ pip install django-uicomponents

Add django_uicomponents to your INSTALLED_APPS.

# settings.py

INSTALLED_APPS = [
    ...
    'django_uicomponents',
    ...
]

Settings

Option Description Default
COMPONENTS_DIR Directory inside your template dir from which components are loaded. 'components'

License

Released under the MIT license.

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

django-uicomponents-0.1.0.tar.gz (4.6 kB view hashes)

Uploaded Source

Built Distribution

django_uicomponents-0.1.0-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page