Pjax(https://github.com/defunkt/jquery-pjax) is a jQuery plugin a standalone JavaScript module that uses ajax (XmlHttpRequest) and pushState() to deliver a fast browsing experience.
Typically django serves each page with a entire page reload, costing performance. Using Pjax, its we convert our django application into a light weight server rendered SPA :) , Lets know how awesome is that..
Here is how to use it and code is hosted at https://github.com/rrmerugu/django-pjaxified.
Step1: Fork and Clone the repo
git clone https://github.com/rrmerugu/django-pjaxified
Step2: Create virtualenv
virtualenv venv
Step3: Activate the
venv
and install the necessary packages usingsource venv/bin/activate && pip install -r requirements.txt
Step4: start the server :D, all the configs are already added into the
settings
. Just start the server withpython manage.py runserver
Check the
djangoajax/settings.py
for thepjax
settings. there are only 3 settings needed . Check https://github.com/nigma/django-easy-pjax for settings and implementation doc.website/templates/base.html
contains thejs
libraries and code needed to activate the pjax on page :) .In the
url/route of django view
while extending thebase.html
instead of{ % extend s "base.html" % }
use{ % extend s "base.html"|pjax:request % }
and place the{ % block content % }
ofbase.html
in a div container with id specified inbase.html
which ispjax-container
in our case.
Try it out, and let me know :)
Last modified on 2017-02-25