Skip to main content

This is a Django helper for defunkt’s jquery-pjax.

Django-PJAX requires Django 1.3.

What’s PJAX?

PJAX is essentially AHAH (“Asynchronous HTML and HTTP”), except with real permalinks and a working back button. It lets you load just a portion of a page (so things are faster) while still maintaining the usability of real links.

A demo makes more sense, so check out the one defunkt put together

Usage

First, read about how to use jQuery-PJAX and pick one of the techniques there.

Next, make sure the views you’re PJAXing are using TemplateResponse. You can’t use Django-PJAX with a normal HttpResponse; only TemplateResponse. Decorate these views with the pjax decorator:

from djpjax import pjax

@pjax()
def my_view(request):
    return TemplateResponse(request, "template.html", {'my': 'context'})

After doing this, if the request is made via jQuery-PJAX, the @pjax() decorator will automatically swap out template.html for template-pjax.html.

More formally: if the request is a PJAX request, the template used in your TemplateResponse will be replaced with one with -pjax before the file extension. So template.html becomes template-pjax.html, my.template.xml becomes my.template-pjax.xml, etc. If there’s no file extension, the template name will just be suffixed with -pjax.

You can also manually pick a PJAX template by passing it as an argument to the decorator:

from djpjax import pjax

@pjax("pjax.html")
def my_view(request):
    return TemplateResponse(request, "template.html", {'my': 'context'})

If you’d like to use Django 1.3’s class-based views instead, a PJAX Mixin class is provided as well. Simply use PJAXResponseMixin where you would normally have used TemplateResponseMixin, and your template_name will be treated the same way as above. You can alternately provide a pjax_template_name class variable if you want a specific template used for PJAX responses:

from django.views.generic import View
from djpjax import PJAXResponseMixin

class MyView(PJAXResponseMixin, View):
    template_name = "template.html"
    pjax_template_name = "pjax.html"

    def get(self, request):
        return self.render_to_response({'my': 'context'})

That’s it!

Release files for django-pjax 1.1

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-pjax 1.1
File Size Uploaded
django-pjax-1.1.tar.gz 3.0 kB Details

Release files / django-pjax-1.1.tar.gz

Download URL django-pjax-1.1.tar.gz
Size 3.0 kB
Tags Source
SHA-256 checksum
How to use checksums
97f4536b18ac52ac6835f5d280d4ca4495d15deaac60e57abba38b86889dca14
BLAKE2b-256 checksum
How to use checksums
b79475fec6bd379845b036edaa1495ea892e6ea44d8f53a12673c985fe983c39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

1.7

2 release files

1.5

2 release files

1.4

1 release file

1.3

1 release file

1.2

1 release file

This release

1.1 This release

1 release file

1.0

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