Skip to main content

ABOUT

django_ajax provides some basic structure to make working with AJAX (and Javascript in general) more easy.

HOW

django_ajax provides various utils.

render_to_json

render_to_json is both implemented as a view and a decorator. The view does the real work, while the decorator is a utility function which itself uses the view to convert objects to json.

The view expects two arguments:

  • request

  • the object to output as JSON

It sets some HTTP headers to make sure the JSON can be loaded everywhere and nothing is cached in the browser.

The decorator just calls the original view function. If the response is not already a HttpResponse, it will be passed through the view as described above.

{% json %}

Template tag to render various objects as JSON.

Syntax:

<script type="text/javascript">
        var obj_as_json = {% json object %};
</script>

<script type="text/javascript">
        {# Output "null" of variable does not exist (prevents JS error) #}
        var obj_as_json = {% json object or null %};
</script>

{% ajax_cache %}

Utility template tag to pass objects to some JS function. May be used to implement JS-side caching of objects. This will speed up JS-driven apps, as the template can put out JS-objects then they are needed anyways. The tag makes sure every object will only be cached once, multiple calls will only output one JS-call.

Syntax:

<script type="text/javascript">
        {% comment %}
                Will output the same as "some_func.to.call({% json object %});"
                But only if object was not used in combination with
                "some_func.to.call" before.
        {% endcomment %}
        {% ajax_cache object using "some_func.to.call" %}
</script>

ajax_processors

Like context_processors, but used to put variables into the JS context. Provides JS_CONTEXT via a context processor, which can be rendered using {% json JS_CONTEXT %}. Example:

<script type="text/javascript">
        var config = {% json JS_CONTEXT %};
</script>

Uses settings.AJAX_CONFIG_PROCESSORS, which uses the same syntax as for context processors.

dango_ajax comes with three ajax processors (living in django_ajax.ajax_processors):

  • media: provides MEDIA_URL

  • static: provides STATIC_URL

  • session: provides basic authentcation information

    • includes AJAX login/logout urls and views

API

Uses object.ajax_data() in various places to allow defining method to convert models/… into dictionaries, which can be converted to JSON. This way you may pass model instances directly to {% json %} and the model may define which data to output.

Metadata

Release files for django_ajax 0.3.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_ajax 0.3.0
File Size Uploaded Provenance
django_ajax-0.3.0.tar.gz 5.2 kB Without provenance Details

Release files / django_ajax-0.3.0.tar.gz

Download URL django_ajax-0.3.0.tar.gz
Size 5.2 kB
Tags Source
SHA-256 checksum
How to use checksums
f45a4c5b0240a0c5e0e088e056e71ec3b381bbd8fa2e6b2bc307c9ff6b64bf33
BLAKE2b-256 checksum
How to use checksums
a6f4f1ad940444e0691d125d205d001f49e1ce5e0feb0b19cc227766908e7aa2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.4.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15

Security for django_ajax 0.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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