我在OpenERP框架中創建了控制器。以下是我的代碼,我設置http.routetype="http"
,OpenERP @ http.route('demo_json',type =「json」)不顯示JSON數據的URL
import openerp.http as http
from openerp.http import request
class MyController(http.Controller):
@http.route('demo_html', type="http")
def some_html(self):
return "<h1>This is a test</h1>"
上面的代碼工作完美的一次,我登錄到的OpenERP後,我修改URL http://localhost:8069/demo_html
告訴我在H1標題標籤返回結果This is a test
。
但是同樣我也嘗試type="json"
並添加以下代碼JSON,並再次嘗試調用URL http://localhost:8069/demo_json
它不能正常工作,給我錯誤"Internal Server Error"
。
import openerp.http as http
from openerp.http import request
class MyController(http.Controller):
@http.route('demo_html', type="http") // Work Pefrect when I call this URL
def some_html(self):
return "<h1>This is a test</h1>"
@http.route('demo_json', type="json") // Not working when I call this URL
def some_json(self):
return {"sample_dictionary": "This is a sample JSON dictionary"}
所以我的問題是如何路由JSON。任何幫助將不勝感激謝謝。
你檢查我回JSON數據返回{「sample_dictionary」:「這是一個示例JSON字典」} –