This question has been flagged
2 Replies
22108 Views

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 . . ??

Avatar
Discard
Best Answer

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.

Avatar
Discard
Best Answer

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.

Avatar
Discard