实习第8天:
早上开始学习jinja:
在odoo10/ws_training/controllers/main.py作为每个前端页面与后台交互的支点,有许多个通过以下方式,例如:
@http.route('/ws_training/signin', type='http', auth='public', csrf=False)
def signin(self, **kwargs):
这样的形式路由的函数
那么具体的前端后台交互式如何实现的呢。
关注到main.py中的代码结构:
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
#参考: http://blog.csdn.net/u011760056/article/details/46969883
#BASE_DIR = "/Users/liuwanli/odoo10/wens_app/ws_training"
templateLoader = FileSystemLoader(searchpath=BASE_DIR + "/templates")
#在"/Users/liuwanli/odoo10/wens_app/ws_training/templates" 中加载文件
env = Environment(loader=templateLoader)
class MainController(http.Controller):
def … #定义各种函数
def …
.
.
.
先看到类的外部定义, 文件系统的结构我们可以先不管,看到这个Environment对象,查看源码,在
/library/Python/2.7/site-packages/jinja2/environment.py中,源码结构复杂,先看到基本结构是: