I have a string like:
daily_program = "{"Training Set":["abc","dxf","gfh"],"Nutrition Set":["acd","dbd","cdf"]}"
I want to use it as a context dictionary and pass it to the template in Django. Such as:
def program(request):
context = json.loads(daily_program)
return render_to_response('program.html',context,RequestContext(request))
Its acting like python Dict. when I print out the result. But I cant use it as a context in template such as:
<div>{{Training}}</div>
Is there any way to is use json object as a context dictionary ?
dialy_program
应该这样阅读,用单引号''
来避免在构建字符串时出现语法错误:
daily_program = '{"Training":["abc","dxf","gfh"],"Nutrition":["acd","dbd","cdf"]}'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.