2017-02-10 46 views
-1

我使用燒瓶構建JSON數據並在網絡上顯示它和下面是我的代碼如何設置響應頭在瓶JSON輸出 - 蟒蛇

result = {"user1": mydata} 
q = json.dumps(result) 

而下面是我的應用程序路徑

@app.route('/contact') 
def contact(): 
"""Renders the contact page.""" 
return render_template(
    'view.html', 
    title='View Json Data', 
    message='Your Data page.', 
    q=q 
) 

當看到網絡上我的網頁響應它是未來的

{"mydata": [{"geoipip": "136.1.1.103","alertid": "1456772324.47092", "timestamp": "2016-09-22T00:28:44.000Z"}]} 

我需要在任何地方設置內容類型爲JSON。請幫助

在此先感謝

+0

http://stackoverflow.com/questions/25860304/how-do-i-set-response-headers-in-flask –

+0

如果你真的是想要在HTML頁面中呈現JSON,那麼它是http://stackoverflow.com/questions/35555383/javascript-raises-syntaxerror-with-json-rendered-in-jinja-template的副本。 – davidism

回答