Skip to main content

django-async-include

License Maintenance made-with-python PyPI pyversions PyPI version gelidum PyPI status PyPI download month Maintainability Test Coverage

Asynchronous inclusion of Django templates

What's this?

This is a project to help the ajax load of chunks of HTML with minimal effort on the developer side, providing an easy way to improve web-site experience for your users by minimizing perceived loading times.

This is the development repository.

How does it work?

The async_include template tag sends the context to the server using an AJAX request.

In the case of model objects, it sends the model, application and id. In the case of QuerySets, it sends the encrypted parametrized SQL. Of course, in the case of safe values like strings, booleans or numbers this data are sent "as is".

The receiver is a basic view of this application that renders the template with the received context and returns it in the AJAX call.

Requirements

This application only depends on pycryptodome.

Of course, you will need Django version 1.10 or newer.

jQuery

No jQuery is required as of version 0.6.6.

Fontawesome (optional)

Fontawesome is the the-facto standard of font icons of our time. Include it in your project to see the spinner moving when loading the remote templates.

The easiest way to include it by using a CDN. For example, bootstrap CDN (not affiliated, nor they endorse this project) is one of the most known.

Default waiting spinner uses fontawesome. You can overwrite async_include/spinner.html template if don't want to use the default fontawesome style.

Installation

Using pip

This package is in pypi so you only have to write:

pip install django-async-include

to install it.

Install master version

Include this code in your requirements.txt file:

-e git://github.com/diegojromerolopez/django-async-include.git#egg=django_async_include

Installation in your Django project

Include the application in your project's settings.py:

INSTALLED_APPS = [
    ## ...
    'async_include',
]

Include django-async-include URLs

Include the URLs of Django-Async-Include in your urls.py project in the namespace async_include:

from django.urls import path, include

urlpatterns = [
    # ...
    path(r'async_include/', include('async_include.urls', namespace="async_include")),
]

Use

Load the async_include template tags at the top of your file and use the async_include template tag as a replacement of the django include template tag.

You have to pass the local context explicitly to the async included templates, so you can pass all variables you need in your included template as named parameters of the async_include template tag.

{# Load the async_include template tag at the top of your template file #}
{% load async_include %}

{# Call the async_include template tag indicating what objects needs to replace it #}
{% async_include "<path of the >" <object1_name>=<object1> <object2_name>=<object2> ... <objectN_name>=<objectN>  %}

There is also a repository with a full example: django-async-include-example.

Call javascript function whe load is completed

Pass the attribute onload with the name of the function you want to call after the request and the replacement has been completed. e.g.

{% async_include "boards/components/view/current_percentage_of_completion.html" board=board onload="load_board_style" %}

Warning and limitations

Object dynamic attributes

No dynamic attribute will be passed to the templates given that only a reference to it is passed from the caller to the included template callee. Don't use dynamic attributes inside an async_included template.

However, the full object will be passed to the async_included template, so you could call its methods and properties without any problem.

QuerySets

Each QuerySet is passed as encrypted SQL and converted on the receiver to a RawQuerySet.

Note that RawQuerySets have no len method so length filter returns always 0.

To fix this we have implemented a new version of the length filter that will be loaded in your template if you overwrite it.

{% load async_included %}

Note that this templatetag file is async_included, ending in ed.

Examples

Passing an object

{% load async_include %}

{# .. #}

{# Load the template and informs the board object is required for the included template  #}
{% async_include "boards/components/view/current_percentage_of_completion.html" board=board %}

Passing a QuerySet

{% load async_include %}

{# .. #}

{% async_include "boards/components/view/summary.html" board=board member=member next_due_date_cards=next_due_date_cards %}

Customization

Spinner

Overwrite async_include/spinner.html template if you want to change the spinner from fontawesome one (default) by a background image or an image. Otherwise, make sure you are loading fontawesome fonts.

Note that the spinner must have class async_included-spinner. Otherwise, the spinner behavior is going to be unpredictable.

Show/Hide spinner

Including the optional parameter spinner__visible=False when calling the async_include template tag will not show the spinner block.

{% load async_include %}

{# .. #}

{# Will not show the spinner #}
{% async_include "boards/components/view/last_comments.html" board=board spinner__visible=False %}

Customize spinner template per async_include template tag call

Use the optional parameter spinner__template_path to set a different template path for a specific async_include call in your templates.

{% load async_include %}

{# .. #}

{# Will not show the spinner #}
{% async_include "boards/components/view/last_comments.html" board=board spinner__template_path="templates/comments/last_comments_spinner.html" %}

Remember the spinner tag should contain the async_included-spinner class.

Block wrapper html tag

Wrapper tag is div and maybe you don't want that. Set html__tag optional parameter to the name of the tag you need in that particular context.

Example:

{% load async_include %}

{# .. #}

{# Will be replaced by <li></li> block instead of <div></div> #}
{% async_include "boards/components/view/last_comments.html" board=board html__tag='li' %}

Block wrapper html tag class

Customize the wrapper class by passing html__tag__class optional parameter to the template tag.

{% load async_include %}

{# .. #}

{# Will be replaced by <li></li> block instead of <div></div> #}
{# Class last_comments will be added to wrapper class #}
{% async_include "boards/components/view/last_comments.html" board=board html__tag='li' html__tag__class='last_comments' %}

## Request frequency

If do you want to make frequent requests, set request__frequency to the number of seconds you want to make the requests.

Example:

{% load async_include %}

{# .. #}

{# Update the last comments each 60 seconds #}
{% async_include "boards/components/view/last_comments.html" board=board request__frequency=60 %}

Development

To run the development tools, we provide a root-level Makefile with the following commands:

  • Run Unit Tests:
    make test-unit
    
  • Run E2E Tests (in Docker Compose):
    make test-e2e
    
  • Run Linters and Formatters:
    make lint
    

Main author

Diego J. Romero-López is a Software Engineer based on Madrid (Spain).

This project is in no way endorsed or related in any way to my past or current employers.

Contact me by email at diegojREMOVETHISromerolopezREMOVETHIS@gmail.com.

Contributors

  • Erik Telepovský:
    • Bug fixes.
    • Modern mobile browser support.
    • PyPy configuration fixes.
    • Python3 support.
    • Multi-language support.

Metadata

Release files for django-async-include 0.8.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-async-include 0.8.0
File Size Uploaded
django_async_include-0.8.0.tar.gz 14.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-async-include 0.8.0
File Interpreter ABI Platform
django_async_include-0.8.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.2 kB

Release files / django_async_include-0.8.0.tar.gz

Download URL django_async_include-0.8.0.tar.gz
Size 14.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ff474e21c0be0e30ea03fad5de2d523c672f59ea6268d76a9d76438acb757442
BLAKE2b-256 checksum
How to use checksums
12300a05474a6892a5fffcef2f29d7e365db2339aa853afced06c2bf810f7cac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Release files / django_async_include-0.8.0-py3-none-any.whl

Download URL django_async_include-0.8.0-py3-none-any.whl
Size 13.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbcefce4c7bcd2a9170bcc1d3d438c8c83407175c576359a8136d001d1964932
BLAKE2b-256 checksum
How to use checksums
5e8129c60801b2974604bfcbe33885b0ec033321a09b0ba41562b083414ec8c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jun 2, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.8.0 This release

2 release files

0.7.0

1 release file

0.6.10

1 release file

0.6.9

1 release file

0.6.8

1 release file

0.6.7

1 release file

0.6.6

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.1

1 release file

0.6

1 release file

0.5.3

1 release file

0.5.1

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page