Skip to main content

Django-Live-Templates is an extension to Django and Channels which adds support for live updating Django template snippets on model changes.

Project description

Django-Live-Templates is an extension to Django and Channels which adds support for live updating Django template snippets on model changes.

This project is based upon and a partial reimplementation to Channels of SwampDragon-live which was build using SwampDragon with SwampDragon-auth and django-redis.

Installation

Install the latest version from pypi.python.org:

pip install django-live-templates

Install the development version by cloning the source from github.com:

pip install git+https://github.com/mback2k/django-live-templates.git

Configuration

Add the package to your INSTALLED_APPS:

INSTALLED_APPS += (
    'channels',
    'django_live_templates',
)

Example

Make sure to use django-redis as a Cache backend named 'django-live-templates' or 'default':

CACHES = {
    'django-live-templates': {
        'BACKEND': 'django_redis.cache.RedisCache',
        'LOCATION': 'redis://localhost:6379/0',
        'OPTIONS': {
            'CLIENT_CLASS': 'django_redis.client.DefaultClient',
        }
    }
}

Load the required JavaScript template-tags within your Django template:

{% load django_live_template %}

Add the required JavaScript to your Django template:

<script type="text/javascript" src="{{ STATIC_URL }}js/django_live_template.js"></script>

Use the include_live template-tag instead of the default include template-tag, with rows being a Django database QuerySet to listen for added, changed, deleted instances:

{% include_live 'includes/table_body.html' rows=rows perms=perms %}

Use the include_live template-tag instead of the default include template-tag, with row being a single Django database Model instance to listen for changes:

{% include_live 'includes/row_cols.html' row=row perms=perms %}

Use the django_live_template variable within the included template to add the required classes to the root-tag of this template, e.g. the first tag-node:

<tr class="{{ django_live_template }}">...</tr>

You can check if your template is being live rendered by a content pusher by using the context variable is_django_live_template like this:

{% if is_django_live_template %}
<style onload="alert('Hello World!');"></style>
{% endif %}

A real-world example can be found in the Django project WebGCal:

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-live-templates-0.0.1a0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

django_live_templates-0.0.1a0-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file django-live-templates-0.0.1a0.tar.gz.

File metadata

  • Download URL: django-live-templates-0.0.1a0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1

File hashes

Hashes for django-live-templates-0.0.1a0.tar.gz
Algorithm Hash digest
SHA256 e8b8fff592657893b69a6e152ac996e8b0362810ecb56caba1acdbe67a39a639
MD5 9091a3ce56b8c54fbfe8ad5ee408740a
BLAKE2b-256 451916d80a5b2b6fe41f5a5a524b7c4fb898ef13cf5b018864d8147a61cfcff4

See more details on using hashes here.

File details

Details for the file django_live_templates-0.0.1a0-py3-none-any.whl.

File metadata

  • Download URL: django_live_templates-0.0.1a0-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.7.1

File hashes

Hashes for django_live_templates-0.0.1a0-py3-none-any.whl
Algorithm Hash digest
SHA256 fa53a610eaae9dd75a248d07209764ab801c57d65bf1187a848e79d9b09b20d6
MD5 d53ccbc9e2d474987ca39d10558637ea
BLAKE2b-256 25cfdea5ae66b7980987721adf6ca576269725bc3ba4dde8b15505396f8817f5

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