Create simple reusable template components in Django. https://django-components.github.io/django-components
Find a file
2015-06-14 21:35:41 -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 Document some alternate ways to run the tests 2015-06-14 21:35:41 -05: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 tox:

pip install tox

Then run all the tests over all Python versions:

tox

Or just the particular version you wish to test:

tox -e py34

You can also have it watch the directory for changes and re-run the tests:

tox -e py34 -- -f