Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single Page Application using Django

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?

like image 259
Ashish Gupta Avatar asked Aug 19 '14 21:08

Ashish Gupta


People also ask

Can we create single page application using Python?

Single-page applications are split into a frontend and backend. Django can be used for traditional web or as the backend for an SPA. Your Python code on the server side includes managing any sort of business logic, and then you can use the Django ORM and database for storage.

Can I build a desktop app with Django?

Not only JS folks can reuse web tehnologies for desktop applications we can do it too. If you want to create a nice gui and you want to reuse your web tech knowledge try flaskwebgui.

Is Django used for spa?

With Django, you'll be able to create SPAs with professional real-time projects where the logic is in Python. By the end of this Django book, you'll be able to build real-time applications, as well as gaining a solid understanding of WebSockets with Django.


1 Answers

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

`

like image 148
Ashish Gupta Avatar answered Sep 28 '22 09:09

Ashish Gupta