Django returning JSON for AJAX requests

In your views.py you can have a page that return JSON data for AJAX request like this:

from django.http import JsonResponse

def ajax(request):
    data = {}
    data['something'] = 'useful'
    return JsonResponse(data)

This would work fine if you fill the data your self, but if you are getting the data from a model try the following:

from django.core import serializers
def tasks_json(request):
    tasks = Task.objects.all()
    data = serializers.serialize("json", tasks)
    return HttpResponse(data, content_type='application/json')

If you have non trivial application, I would recommend using Django Rest Framework or similar frameworks for better support for REST beyond simple JSON response.

Web based Quran Application

Last week I rediscovered ArabEyes which is a web site dedicated for Arabic UNIX software, they host many Arabic projects.
One of the hosted projects is Quran project, they produced many XML files of Quran text, and they needed help with collecting data, both textual data, and audio data.
So I talked with Abdullah Aldosari about it, and it happened that he have MySQL table with this kind of data, so I processed the table and convert it UTF-8 to be complatible with ArabEyes and UNIX, my plan is to cleanup this data and contibue it back to ArabEyes.
Meanwhile I started playing with this data and created a web based Quran software, please try it out.
Quran
It uses AJAX to make fast and user friendly interface.