views:

51

answers:

1

I'm trying to pass an image's src to a django view when a button is clicked. In my template, I have:

$("#url_submit").click(function() {
   var film = "{{ filmname }}"
   var id = {{ id }}
   $.ajax({
     url: "/db/gallery2/" + film + "/" + id + "/",
     data: {url: $('#large_thumbnail').attr('src')},
     type: "POST"
   });  
});

My view reads:

def thumbnail_choice(request, filmname, id):
    if request.is_ajax:
         if request.method == "POST":
            url = request.POST['url']
            if url != "":
                 mdlnm = get_model('db', filmname.lower())
                 object = get_object_or_404(mdlnm, id__iexact=id)
                 object.url_small = url
                 object.save()
                 return HttpResponseRedirect("/db/")
    return render_to_response('gallery2.html', {'filmname': filmname, 'id': id})

When I submit the page though, I get an error:

"Key 'url' not found in <QueryDict: {}>"

I'm sure there are a combination of things I'm doing wrong here.

A: 

D'Oh. Sorry for wasting your time. Rookie mistake:

if request.is_ajax():

NOT

if request.is_ajax:

Thanks for the comments though

Ed