1👍
✅
You could just put your context as JSON object into itself:
@page_template("app/Discover.html")
def Discover(request, template="app/Discover.html", extra_context=None):
context = {}
context['to_loc']=loc_both
context['to_av']=av_both
context['to_ql']=ql_both
if extra_context is not None:
context.update(extra_context)
ctx_copy = context.copy()
context['context_json'] = simplejson.dumps(ctx_copy)
return render_to_response(template, context, context_instance=RequestContext(request))
And just render it into your template as JavaScript variable:
jsonList = [];
jsonList = {{ context_json|safe }}; // contextJSON holds the context objects that are sent by my view above
print(JSON.stringify(jsonList.to_loc)); // this should give me the data of locations from respective context object
print(JSON.stringify(jsonList.to_av)); // this is for for AV
Source:stackexchange.com