In view.py I am using the below for loop to get json data
tables = [] column = [] list = [] for row in result: d = collections.OrderedDict() schematab = row[0].encode('utf8') + '.' +row[1].encode('utf8') d = schematab tables.append(d) column = [] for row in tables: d1 = collections.OrderedDict() tabcol = row.split('.') query2 = 'call SP_Get_TABCOL_Names('+str(pid)+',"'+str(tabcol[1])+'")' cursor.execute(query2) result2 = cursor.fetchall() for i in result2: d2 = collections.OrderedDict() d2 = i[5] column.append(d2) d1[row] = column list.append(d1) column = [] ..... .... context = RequestContext(request,{'appuser':'admin','result':json.dumps(list)}) return HttpResponse(template.render(context), content_type="text/html") Result of the loop is data in this format
[ { "outlet_db.dim_outlet": ["area , ", "area_mask "], "outlet_db.dim_sales": ["sales1 , ", "sales2 "], "outlet_db.dim_product": ["produt1", "product2"] } ] Now in views.html im using the below loop
{% for key,value in result %} {{key}} {{value}} {% endfor %} This prints only the json keys, but values are empty. I need both keys and values.
json.dumps(), which convertsresultsto a string, then loop through it in the template.