Single Page Application using Django

Ashish Gupta picture Ashish Gupta · Aug 19, 2014 · Viewed 18.4k times · Source

I am using django-easy-pjax for making a Single-Page-Application:

base.html:

{% load staticfiles %}
<script type="text/javascript" src="{% static '/static/js/jquery.js' %}"></script>
<script src="{% static '/static/js/jquery.pjax.js' %}"></script>

{% block side%}
It is {% now "c" %} 
<br><br>
<a href="/uu/">Next Page</a>
<br/></br>
{%endblock side%}


{%block main%}
{%endblock main%}

1.html:

{% extends "base.html"|pjax:request %}
{%block main%}
If time doesnot change Easy pjax is working
{%endblock main%}

views.py:

from django.shortcuts import render
from django.shortcuts import render_to_response
from django.template import RequestContext
from django.template.response import TemplateResponse

def index(request):
  return render_to_response('base.html', {}, context_instance = RequestContext(request))

def index1(request):
  return render_to_response('1.html', {}, context_instance = RequestContext(request))

urls.py:

    (r'^pjax/$', 'app_name.views.index'),
    (r'^uu/$', 'app_name.views.index1'),

But when I click on the next page the time url changes,content gets loaded but time also changes that means easy-pjax is not working.What correction should I make in my code?I have added pjax_base.html template in template dir. But what should be the content of pjax_base.html?Do I need to configure anything else like HTTP header on the server side?If yes how?

Answer

Ashish Gupta picture Ashish Gupta · Jun 25, 2015

Using django-easy-pjax was a bad idea. To make a SPA using django , REST frameworks should be used. I switched to `Django REST Framework. I am using Django+ DjangoRESTFramework + AngularJS for SPA using Django

`