0
在Django我view.py是顯示JSON數據
import json
from django.http import HttpResponse
from django.template import Template, Context
from django.shortcuts import render_to_response
def ajax(request):
obj =[dict(a = 1,b = 2)]
jsons=json.dumps(obj)
print jsons
return render_to_response("2.html", {"obj_as_json": jsons})
我想顯示A和B是JSON在我的模板2.HTML的價值。請幫我寫代碼。
你可以通過'obj'到模板,並告訴他們爲'{{obj.a}} ' – Rohan