title: Django Ajax return error messages
body: <p>How would i return error message with django?
  I am thinking something like this ( i am using jsonresponse just as an example of how i want to do this):</p>
  
  <pre><code>def test(request):
  if request.method == "POST":
      if form.is_valid():
        form.save
        return JsonResponse({"message":"Successfully published"})
      else:
           '''here i would like to return error something like:'''
          return JsonResponse({"success": false, "error": "there was an error"})
  else:
      return JsonResponse({"success}: false, "error": "Request method is not post"})
  </code></pre>
  
  <p>What I am trying to achieve is to render error messages in template from ajax error function. Something like this:</p>
  
  <pre><code>$("#form").on("submit", function(){
          $.ajax({url: "url",
                  data: ("#form").serialize,
                 success: function(data){
                 alert(data.message);  
                 },
                 error: function(data){
                 alert(data.error);
                 }
               });
  </code></pre>
  
  <p>Would that be possible?</p>