def createThread(request): response = {} try: title = request.POST.get("title") body = request.POST.get("body") except: response["result"] = "failure" response["errors"] = "Missing data from template." return HttpResponse(json.dumps(response)) t = Thread() t.name = title t.save() c = Comment() c.owner = request.user c.thread = t c.index = 0 c.body = body c.save() response["result"] = "success" response["thread_id"] = t.id return HttpResponse(json.dumps(response))