#views.py from django.shortcuts import render_to_response from django.shortcuts import get_object_or_404 from django.http import HttpResponse, Http404 from django.template.loader import get_template from django.template import RequestContext from django.template import Context from django.utils import simplejson from forms import MyForm def ajax_view(request): """ handles the ajax """ template = 'mytemplate/page.html' if request.is_ajax(): if request.method == 'POST': post = request.POST my_form = MyForm(request.POST) if my_form.is_valid(): new = my_form.save(commit=True) response = { 'status':True, } else: response = { 'status':False } json = simplejson.dumps(response, ensure_ascii=False) return HttpResponse(json, mimetype="application/json") context = {'my_form':my_form} return render_to_response(template, context, context_instance=RequestContext(request)) else: raise Http404 #urls.py from django.conf.urls.defaults import * from views import ajax_view urlpatterns = patterns('', url(r'^$', ajax_view, name="ajax_view"), ) #page.html