This might be a silly question but I'm rather new to JavaScript.. I have an JSON encoded response of a python dictionairy which I want to use to inject as data in my javascript

However the django return consists of string with a header AND hashmap

HOW, but more importantly WHERE should the logic of stripping this down to usable data take place? (All I want is the map)

  • In views.py (my entire way of returning a JSON object should be revised)
  • In template (my approach is okay but I should write a custom filter)
  • In my html (I should strip the result of it's header within the javascript on doc load)

Thanks

edit:

the jQuery part

var chart;
$(document).ready(function() {
    chart = new Mycharts.Chart({
        chart: {
            renderTo: 'container',
            defaultSeriesType: 'bar'
        },
        settings: {
             data: [],
        },
    ...

the view

data = assemble_dict()
testVar2 = json_response(data)
return render_to_response('home.html', { "testVar": testVar, "testVar2": testVar2 })

the applogic

def assemble_dict():
    data = {}
    objects = Balance.objects.all()
    for obj in objects:
        data[obj.name.name_bank] = obj.money
    return data

def json_response(*args):
    return HttpResponse(
        simplejson.dumps(args),
    )

this is what I get back now from {{ testVar2 }}: Content-Type: text/html; charset=utf-8 [{"Stuff": 50, "MoreStuff": 3}]

link|improve this question
Can you post a sample of the data structure? – jnpcl May 14 '11 at 9:47
"the django return consists of string with a header AND hashmap" What? – Ignacio Vazquez-Abrams May 14 '11 at 10:04
feedback

1 Answer

Why is your view separate from the (I presume you mean) app logic? Seems like your json_response function is a view, in that it is returning an HttpResponse. You either need to directly return the value from json_response, or leave out the HttpResponse call in that function.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.