I make some simple web with flask (for educational purpose). when I try to assign a string value inside a python dict, all apostrophe(') change into '. here is my dummy code:
@app.route('/')
def index():
a={}
dummy=[]
dummy2={}
dummy2['SGD']='testing'
dummy2['USD']='testingagain'
dummy.append(dummy2)
a['lalala']=dummy
dummy=[]
dummy3={}
dummy3['SGD']='testtillbored'
dummy3['USD']='testtillbored2'
dummy.append(dummy3)
a['lalalala']=dummy
return render_template('main.html',**locals())
and my main.html:
<!DOCTYPE HTML>
<html>
<meta charset='utf-8'>
<body>
<script>
var x={{a}};
console.log(x);
</script>
</body></html>
Actually, I have succeeded in getting data when I using Ajax call. So I dump the dict into json and catch it when the webpage loads. So my question is, how to get the data in json without having to use ajax call?