我在 OpenERP 框架中创建控制器。以下是我的代码,我设置了 http.route type="http"
,
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>"
一旦我在修改 URL 后登录到 openerp,上面的代码就可以完美运行,显示我在 h1 标题标签中http://localhost:8069/demo_html
返回结果。This is a test
但同样我尝试type="json"
添加以下 json 代码并再次尝试调用 URLhttp://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。任何帮助将不胜感激谢谢。