Odoo Help


why use in http.route() attribute as type="json"

Dasadiya Chaitanya
on 3/24/14, 7:21 AM 7,139 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 . . ??

Mustafa Kantawala
On 2/2/15, 7:28 AM

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.


Hello Dasadiya Chaitanya,


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.


As compred to JSON, http will pass http request arguments to http.route() not json data.


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

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

2 follower(s)


Asked: 3/24/14, 7:21 AM
Seen: 7139 times
Last updated: 9/13/17, 6:21 AM