This article seems like a pretty good guide to working with ajax and regular requests. The object requesthas a method is_ajax()that will search HTTP_X_REQUESTED_WITH: XMLHttpRequest. This, of course, will depend on how correctly these values ββare set when sending a javascript request.
From the article:
from django.http import HttpResponse
from django.core import serializers
from django.shortcuts import render_to_response
from your_app.models import ExampleModel
def xhr_test(request, format):
obj = ExampleModel.objects.all()
if request.is_ajax():
data = serializers.serialize('json', obj)
return HttpResponse(data,'json')
else:
return render_to_response('template.html', {'obj':obj}, context=...)
django-piston, RESTful Django. . ( ), mime- , URL-, html, xml, json. , , ( ) .