Take the 2-minute tour ×

Building a site so users can add topics onto a site and ask then Q&A. Using AJAX, the "Add Media" button on the home page loads my Add Media Form (text and an image) to the site. The box is rendering fine with the correct forms, but after hitting Submit the form doesn't save in the database. When just rendering the form onto a new HTML page without jquery, the model works just fine and the input is saved. How do I get the information submitted in a jquery lightbox to be saved in the database too?

So this is the html page

<a href="#login-box" class="btn btn-success">Add Media</a>  
        <div id="login-box" class="addmovie-popup">

This is the jquery that goes with it

$(document).ready(function() {
    $('.block3 a').click(function(ev) {

The URL conf

url(r'^add_media/$', 'add_media'),

The view for adding media

def add_media(request):
    if request.method == "POST":
        form = MediaForm(request.POST, request.FILES)   
        if form.is_valid():
            form.save(user = request.user)
            return HttpResponseRedirect("/home//")
        form = MediaForm()
        return render_to_response("qanda/add_media.html", {'form': form}, context_instance = RequestContext(request))

And the HTML form that it is rendering

<h1> Add Media:</h1>
    {{ form.as_p }}
share|improve this question

1 Answer 1

up vote 0 down vote accepted

If you're loading HTML into your page dynamically action = "" would point to the current page, which clearly doesn't handle your POST requests.

Set the action to the correct URL.

share|improve this answer
So I tried action = "/home/", action = "/localhost/home/" and neither worked. Some help please? Thanks! –  Chris Yin Nov 1 '12 at 7:35
I think the correct url for action is /add_media/ –  jpic Nov 1 '12 at 7:46
@jpic was right (although my urlconf poitns to /home/add_media/), still right. awesome thanks! –  Chris Yin Nov 1 '12 at 8:19

Your Answer


