Convert a SQL query to JSON and iterate it in Django

0

I have a query that I perform on a link to an API and it returns a result in STRING, what I want to do is convert it to JSON and iterate it to be able to handle each result of that query individually.

Right now in the views I have:

url = "http://enlaceamiapiinterna/"

miQuery = "SELECT TOP 10 usuarios FROM mibbdd"


queryResult = http.request('GET', url+miQuery)

    json_data = json.loads(queryResult.data.decode('utf-8'))
    json_data2 = json.dumps(dict(json_data))
    print(json.dumps(dict(json_data)))

    context = {
        'order_list': orders,
        'engineer_list': engineers,
        'customer_list': customers,
        'current_user': currentUser,
        'engineers_availables': engineersAvailables,
        'ticket_form': form,
        'success_message': success_message,
        'json': json_data

    }
    return render(request, 'order/calendar.html', context)

And in the template I have:

<div>{{ json.data }}</div>

But right now it returns all the results I would like to iterate for each result individually to be able to distinguish them as needed

    
asked by Grim Nero 15.05.2018 в 10:19
source

0 answers