openerp(odoo8) 框架,路由加载失败问题
openerp框架,路由问题:
若未将路由所在的模块强制加载到root类中,并且未在访问路由的时候传headers信息:Cookie:{session_id: ‘xxx’},就会导致状态码为404的错误。
解决办法:
修改openerp框架下的http.py中的root类,把路由所在的模块强制加载进来。
self.nodb_routing_map = routing_map([’’, “web”,“xxx”,], True)
class Root(object):
"""Root WSGI application for the OpenERP Web Client.
"""
def __init__(self):
# Setup http sessions
path = session_path()
_logger.debug('HTTP sessions stored in: %s', path)
self.session_store = werkzeug.contrib.sessions.FilesystemSessionStore(path, session_class=OpenERPSession)
# TODO should we move this to ir.http so that only configured modules are served ?
_logger.info("HTTP Configuring static files")
self.load_addons()
_logger.info("Generating nondb routing")
# **************************************将路由所在模块添加到此处
self.nodb_routing_map = routing_map(['', "web","xxx",], True)
# **************************************
def __call__(self, environ, start_response):
""" Handle a WSGI request
"""
return self.dispatch(environ, start_response)
def load_addons(self):
""" Load all addons from addons patch containg static files and
controllers and configure them. """
statics = {}
for addons_path in openerp.modules.module.ad_paths:
for module in sorted(os.listdir(str(addons_path))):
if module not in addons_module:
manifest_path = os.path.join(addons_path, module, '__openerp__.py')
path_static = os.path.join(addons_path, module, 'static')
if os.path.isfile(manifest_path) and os.path.isdir(path_static):
manifest = ast.literal_eval(open(manifest_path).read())
manifest['addons_path'] = addons_path
_logger.debug("Loading %s", module)
if 'openerp.addons' in sys.modules:
m = __import__('openerp.addons.' + module)
addons_module[module] = m
addons_manifest[module] = manifest
statics['/%s/static' % module] = path_static
app = werkzeug.wsgi.SharedDataMiddleware(self.dispatch, statics)
self.dispatch = DisableCacheMiddleware(app)