Create simple reusable template components in Django. https://django-components.github.io/django-components
Find a file
Ryan Hiebert 0f52cb845e More clearly define support
This started out as a plan to support Django 1.7 and 1.8, and on all
current versions of Python. This turned into supporting Django 1.8 on
Python 2.7, 3.3, and 3.4 only.

The tests don't pass under Django 1.7 because 1.8 introduced new
settings for configuring templates. Because of this the install_requires
section of setup.py declares that it must be using Django 1.8+.

Python 3.3 support was added, since that's a supported version of Python
under Django 1.8.

Also added pytest-xdist to the tox dependencies, to support running

    tox -e py34 -- -f

in order to have it watch and rerun the tests in development.
2015-06-14 21:25:27 -05:00
django_components Add component tag. 2015-06-14 14:43:57 +02:00
tests Add component tag. 2015-06-14 14:43:57 +02:00
.gitignore Add GitHubs default gitignore. 2015-06-11 19:58:44 +02:00
.travis.yml More clearly define support 2015-06-14 21:25:27 -05:00
README.md Make docs easier to understand by removing blocks. 2015-06-14 14:49:39 +02:00
setup.py More clearly define support 2015-06-14 21:25:27 -05:00
tox.ini More clearly define support 2015-06-14 21:25:27 -05:00

django-components

A way to create simple reusable template components in Django.

Installation

pip install django-components (NOTE: Does not work yet)

Usage

Start by creating a Component by inheriting from the Component class. Don't forget to register the component so that it's available in the templates.

from django_components import component

class Calendar(component.Component):
    def context(self, date):
        return {
            "date": date,
        }

    class Media:
        template = "[your app]/components/calendar/calendar.html"
        css = {'all': ('[your app]/components/calendar/calendar.css',)}
        js = ('[your app]/components/calendar/calendar.js',)

component.registry.register(name="calendar", component=Calendar)

In your templates, use your component by first importing the django_components tag library, and then using the component_dependencies and component tags to render the component to the page.

{% load django_components %}
<!DOCTYPE html>
<html>
<head>
    <title>My example calendar</title>
    {% component_dependencies %}
</head>
<body>
    {% component name="calendar" date=custom_date1 %}
    {% component name="calendar" date=custom_date2 %}
</body>
<html>

Running the tests

Install and run tox:

pip install tox
tox