title: Django jquery form submissions returning 500
body: <p>I am trying to do a modelform submission is Django with jquery and I am getting a 500 server response and not sure how to proceed.</p>
  
  <p>This is my js:</p>
  
  <pre><code>function addUpdate(e) {
      e.preventDefault();
      var form = jQuery(e.target);
      jQuery.ajax({
          url: form.attr('action'),
          type: form.attr('method'),
          data: form.serialize(),
          dataType: 'json',
          success: function(){
              $('&lt;p&gt;Been Added&lt;/p&gt;').insertBefore("div.tr-list");
          }
      });
  };
  
  jQuery("form#tr-form").submit(function(e){
      addUpdate(e);
  });
  </code></pre>
  
  <p>This is my form:</p>
  
  <pre><code>&lt;input class="nidden" type="button" id="tr-trigger" value="Add Resource" /&gt;
  
      &lt;form class="absolute" id="tr-form" action="{% url topic_resource_create topic.person.user topic.slug %}" method="POST"&gt;{% csrf_token %}
      &lt;div id="tr-wrapper"&gt;
          {{ tr_form.as_p }}
  
          &lt;input id="tr-submit" type="submit" value="Submit" /&gt;
          &lt;input type="reset" value="Reset" /&gt;
      &lt;/div&gt;
      &lt;/form&gt;
  </code></pre>
  
  <p>This is my view:</p>
  
  <pre><code>def tr_create_xhr(request, slug):
      if request.method == "POST":
          form = TopicResourceForm(request.POST)
          try:
              r = Resource.objects.get(url=form.cleaned_data['resource'])
          except Resource.DoesNotExist:
              r = Resource.objects.create(url=form.cleaned_data['resource'], rtype=form.cleaned_data['rtype'])
              r.save()
          form.resource = r
          topic = Topic.objects.get(person__user=request.user, slug__iexact=slug)
          form.topic = topic
          if form.is_valid():
              form.save()
          response = serializers.serialize('json', form)
  
      if request.is_ajax():
          return HttpResponse(response, content_type="application/javascript")
      else:
          return HttpResponseRedirect("../..")
  </code></pre>
  
  <p>I am not sure if they view logic is correct because I get a 500 server error everytime i try and post to the url. I have a couple other similar form submissions that are giving me the same error.</p>