(10)odoo控制器操作
-----------------
更新时间
11:17 2016-09-18 星期日 完善讲解
17:44 2016-02-17 星期三
-----------------
* 控制器Controller
它的功能是拦截浏览器的请求和响应数据的发送
* 一个简单的控制器
from openerp import http
class Mymodule(http.Controller)
@http.route('mymodule/mymodule/', auth='public')
def index(self,**kw)
return "Hello, world"
#return http.request.render("mymodule.index",{'fruits':['apple','banana','pear']})
使用模板
"mymodule.index":指mymodule模块下的标识为index的模板
{'fruits':['apple','banana','pear']}: 带一个字典数据给模板
对应的模板文件
<openerp>
<data>
<template )
def index(self, s_action=None, db=None, **kw):
return http.local_redirect('/web', query=request.params, keep_hash=True)
....
# 跳转
def local_redirect(path, query=None, keep_hash=False, forward_debug=True, code=303):
这是http.py中的,封装了 werkzeug的跳转
def redirect(location, code=302) 这个是werkzeug中的
#得到模型
request.registry['模型名']
menu_data = request.registry['ir.ui.menu'].load_menus(request.cr, request.uid, context=request.context)