博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Odoo 中的 Controller
阅读量:4629 次
发布时间:2019-06-09

本文共 1865 字,大约阅读时间需要 6 分钟。

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 openerpfrom openerp import httpclass 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 openerpfrom openerp import httpfrom openerp.http import local_redirect_with_hashclass 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')

 

转载于:https://www.cnblogs.com/kfx2007/p/4936156.html

你可能感兴趣的文章
Java异常机制
查看>>
BZOJ——1202: [HNOI2005]狡猾的商人
查看>>
php如何定时执行任务
查看>>
一 梳理 从 HDFS 到 MR。
查看>>
[转载]二叉树(BST,AVT,RBT)
查看>>
mac下mysql5.7.10密码问题
查看>>
实验4
查看>>
2017高级软件工程第1次作业
查看>>
Centos6.5基于GPT格式磁盘分区
查看>>
node.js是做什么的?
查看>>
LeetCode之461. Hamming Distance
查看>>
HSSFWorkbook 与 XSSFWorkbook
查看>>
希尔排序——算法系列
查看>>
javascript ES6 新特性之 扩展运算符 三个点 ...
查看>>
数论(Lucas定理) HDOJ 4349 Xiao Ming's Hope
查看>>
Jetson tk1 安装 CUDA,ROS,OpenCV和kinect2以及刷机以及ssh远程控制
查看>>
linux 下byte,char,unsigned char的区别
查看>>
团队任务四(无图)
查看>>
mysql 免安装
查看>>
Introduction to Linux Kernel
查看>>