在static中导入我们的网页模板和css样式
在controllers下创建python文件
# 加载模板
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
folder_path = BASE_DIR + "/static/templates" # 相对文件路径
templateLoader = FileSystemLoader(searchpath=folder_path)
env = Environment(loader=templateLoader)
添加路由
class Website(Website):
# 默认网站
@http.route(['/<string:lang>/index', '/index_ec', '/'], type='http', auth="public", website=True, sitemap=True)
def index_ec(self, lang="zh_CN", **kw):
"""
电商首页
:param kw:
:return:
"""
cr, uid, context, pool = request.cr, odoo.SUPERUSER_ID, request.context, request.env
values = {}
csrf_token = request.csrf_token()
values['csrf_token'] = csrf_token
values['company'] = pool['res.company'].sudo().browse(1)
template = env.get_template('%s/index-2.html' % lang)
html = template.render(object=values)
return html
别忘记更新模块,我们可以在配置中添加这个参数,就不用每次手动更新了
在网站中输入我们刚设置的路由,就OK了
有不懂的可以加群,群里面有资料。
群号:557402829