2

OpenERP Framework でコントローラーを作成しています。以下は私のコードで、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 にログインすると完全に機能し、http://localhost:8069/demo_html結果This is a testが h1 見出しタグで返されることが示されます。

しかし、同じように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 をルーティングする方法です。どんな助けでも感謝しますありがとう。

4

2 に答える 2

1

type="json"これは と の間に違いがあるためtype="http"です。

type="json":

it will call JSONRPC as an argument to http.route() so here , there will be only JSON data be able to pass via JSONRPC, It will only accept json data object as argument. 

type="http":

As compred to JSON, http will pass http request arguments to http.route() not json data.
于 2014-04-01T06:06:38.230 に答える