Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
24007 Widoki

above code from the website_mail module in controller email_designer.py file

from openerp.addons.web import http from openerp.addons.web.http import request

class WebsiteEmailDesigner(http.Controller):

@http.route('/website_mail/email_designer/<model("email.template"):template>/', type='http', auth="user", website=True, multilang=True)
def index(self, template, **kw):
    values = {
        'template': template,
    }
    print 'TEMPLATE DETAIL >>>>>>>>>>>',template
    return request.website.render("website_mail.designer_index", values)

@http.route(['/website_mail/snippets'], type='json', auth="user", website=True)
def snippets(self):
    return request.website._render('website_mail.email_designer_snippets')

my question is can any one explain me why @http.route() method use type="json" and type="http" attribute which situation we are using type="json" in controller and type="http" in controller and why it is require to do . . ??

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Dasadiya Chaitanya, In http.route() type describes which kind of operation do you want to perform.

Type = 'http' returns on another template and it will take dictionary with that. It will take you to the another template with the values and will refresh the page.

And type = 'json' calls from jsonrpc call from javascript and it will only return dictionary. It will not refresh the page and will do all the operation which is described in that method.

Awatar
Odrzuć
Najlepsza odpowiedź

Hello Dasadiya Chaitanya,

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.

Examples

@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"}

I hope it is useful to  you.

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
8
lip 24
20127
3
mar 15
5239
1
mar 15
3711
2
gru 23
21824
1
mar 15
4166