Odoo Help

Welcome!

This community 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.

2

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

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

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

4
Mohit Kotak (MK)
On 2/2/15, 7:48 AM

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.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 3/24/14, 7:21 AM
Seen: 3916 times
Last updated: 5/14/16, 8:18 PM