django-pjax

Software Screenshot:
django-pjax
Software Details:
Version: 1.2
Upload Date: 14 Apr 15
Developer: Jacob Kaplan-Moss
Distribution Type: Freeware
Downloads: 9

Rating: nan/5 (Total Votes: 0)

django-pjax is a Django helper for defunkt's jquery-pjax.

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'})


That's it!

Requirements:

  • Python
  • Django

Other Software of Developer Jacob Kaplan-Moss

Comments to django-pjax

Comments not found
Add Comment
Turn on images!