[Fixed]-Consuming JSON into django view

1πŸ‘

βœ…

The club you need in your template is what you call data in your view:

def clubs(request):
    data = requests.get('http://127.0.0.1:8000/app/clubs/').json()

    context = RequestContext(request, {
        'club': data,
    })

    return render_to_response('imgui/genres.html', context)

Not relevant to the problem itself, but a few hints:

  • This loop:

    count=0
    for i in data:
        count+=1
    

    is equivalent to: count = len(data)

  • This loop:

    for j in range(count):
        g.append(data[j]['club_name'])
        identity.append(data[j]['url'])
    

    can be better written as:

    for c in data:
        g.append(c['club_name'])
        identity.append(c['url'])
    

Leave a comment