Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6607517
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:43+00:00 2026-05-25T19:30:43+00:00

I am trying to do a modelform submission is Django with jquery and I

  • 0

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.

This is my js:

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(){
            $('<p>Been Added</p>').insertBefore("div.tr-list");
        }
    });
};

jQuery("form#tr-form").submit(function(e){
    addUpdate(e);
});

This is my form:

<input class="nidden" type="button" id="tr-trigger" value="Add Resource" />

    <form class="absolute" id="tr-form" action="{% url topic_resource_create topic.person.user topic.slug %}" method="POST">{% csrf_token %}
    <div id="tr-wrapper">
        {{ tr_form.as_p }}

        <input id="tr-submit" type="submit" value="Submit" />
        <input type="reset" value="Reset" />
    </div>
    </form>

This is my view:

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("../..")

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:30:43+00:00Added an answer on May 25, 2026 at 7:30 pm

    Firebug should show you the actual error. However, in this case it seems likely that the problem is in your serialization code. You can’t call serializers.serialize on a form – that makes no sense at all. The serializers work on a queryset.

    What you need to do is get the object returned from saving the form, wrap that in a list, and then serialize it:

    obj = form.save()
    response = serializers.serialize('json', [obj])
    

    However you also have some issues with the flow through your view – there’s no object if the form is not valid, for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Django, I am trying to derive (subclass) a new form from ModelForm form
i am trying to create a signup form for my django app. for this
I'm trying to set up a ModelForm in Django that will use the django-chosen
I'm trying to move from django 1.0.2 to 1.1 and I am getting the
I am trying to use ModelForm: from django.db import models from django.forms import ModelForm
Trying to setup an SSH server on Windows Server 2003. What are some good
Trying to get my css / C# functions to look like this: body {
Trying to find some simple SQL Server PIVOT examples. Most of the examples that
Trying to keep all the presentation stuff in the xhtml on this project and
Trying to do this sort of thing... WHERE username LIKE '%$str%' ...but using bound

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.