zoukankan      html  css  js  c++  java
  • Odoo 中的 Controller

    来自  Odoo处理HTTP请求的接口用的Contoller类,封装于web模块中。

    ---------------------------------------------------------------

    RequestHandler:

    1. replace_request_password(args):用*替换掉request中的密码字符。

    2. dispatch_rpc(service_name, method, params):处理RPC请求。service_name的值可取common,db,object,report四种。

    3. local_redirect(path, query=None, keep_hash=False, forward_debug=True, code=303):重定向到一个新url。

    4. redirect_with_hash(url, code=303):带locathion.hash值的重定向方法。

    ---------------------------------------------------------------

    WebRequest:

    Odoo Web请求的父对象

    属性:httprequest,httpresponse,httpsession,env,context,session,lang,cr,debug,registry_cr,session_id,registry,db

    ---------------------------------------------------------------

    route装饰器:封装了处理web request路由的处理方法,被封装的方法必须为Controller的子类方法。

    route(route=None, **kw):

    参数说明:

    route:字符或数组,映射URL中对应的路径。

    type:request的类型,'http'或'json'。

    auth: 认证方法,可以为以下值:'user','admin','none'.

    methods: http请求方法,默认为都允许。(GET,POST)

    cors:跨域指示值。

    --------------------------------------------------------------

    JsonRequest:WebRequest子类,处理JSON-RPC(http://wiki.geekdream.com/Specification/json-rpc_2.0.html)的类。

    --------------------------------------------------------------

    HttpRequest:WebRequest子类,处理HTTP请求并响应。

    1.make_response:处理非HTML响应或自定义的headers和cookies

    2.render:显示QWeb模板

    3.not_found:404

    例子1:自定义路径/px 返回字符串“Hello Odoo".

    import openerp
    from openerp import http
    
    class px(openerp.addons.web.controllers.main.Home):
    
        @http.route(['/px'],type='http',auth='None')
        def px2(self,*args,**kargs):
            return  'Hello Odoo!'

    例子2:自定义路径/px 重定向到网址 bing.com

    import openerp
    from openerp import http
    from openerp.http import local_redirect_with_hash
    
    class px(openerp.addons.web.controllers.main.Home):
    
        @http.route(['/px'],type='http',auth='public')
        def px2(self,*args,**kargs):
            return  local_redirect_with_hash('http://www.bing.com')
  • 相关阅读:
    蔚来NIO Pilot 全球首试 终于摘掉半成品帽子
    这个机械手可精准灵活地接住一颗掉落的棉花糖并使其“安然无恙”
    谷歌已经领先 那么苹果的人工智能战略又在哪里
    你见过机器船吗?MIT新版ROBOAT可以自动组装
    谷歌、亚马逊、苹果三大语音助手发展现状 谁被甩在身后了
    Python中的十大图像处理工具
    测试用例设计理论
    Flask+Mysql搭建网站之数据库问题
    Flask+Mysql搭建网站之网页设计
    Flask+Mysql搭建网站之安装Mysql
  • 原文地址:https://www.cnblogs.com/chjbbs/p/5937355.html
Copyright © 2011-2022 走看看