Hello everyone,
I've been trying to get some Ajax stuff to work in my Django application, but it has been difficult because for some reason syntax and type errors are not causing a server crash and are failing silently. How could this be?
JavaScript (jQuery):
add_foo = function() {
var numfoos = $("div#foos_container > div.foo").length + 1;
var foo_id = numfoos + "-foo";
var div = $("<div></div>").attr("id",foo_id).addClass("foo");
div.load("http://localhost:8000/ajax/get/url/");
div.appendTo("div#foos_container");
};
Python:
def ajax_add_foo(request):
print request.session['editing_foos'].keys()
keys = request.session['editing_foos'].keys()
if len(keys) == 0:
next_key = 1
else:
next_key = max([ id_from_prefix(key) for key in keys ])
print next_key
form = FooForm(prefix=next_key)
print next_key
request.session['editing_foos'].update( {create_prefix(FooForm, next_key) : -1 } ) # This foo is new and has no pkey
print request.session['editing_foos']
return render_to_response( 'bar/foo_fragment.html',
{'fooform' : fooform, },
context_instance=RequestContext(request))