【1】 调式qweb模板时, 可以脱离openerp环境

阅读一下openerp目录 qweb目录中的几个html文件,可以作为起步

在浏览器下, 可以这样运行这些文件

http://127.0.0.1:8069/web/static/lib/qweb/qweb-benchmark.html

http://127.0.0.1:8069/web/static/lib/qweb/qweb-test.js.html

【2】qweb模板的格式如果不符合xml规范, 浏览器显示空白, 浏览器的控制台中会显示如下提示

Uncaught Error: QWeb2: This page contains the following errors:error on line xxx at column yyy:

然后是具体的错误原因。比如

Opening and ending tag mismatch: aaa  line nnn and bbb

Specification mandate value for attribute ccc

【3】在模板中增加如下指令, 可在浏览器的控制台上输出变量内容

〈t t-log="变量名称" />

当使用多个t-log时, 控制台中输出的变量内容会引起混淆, 这时可再增加如下语句

〈t t-log=" '变量名称的说明' " /> 

【4】在模板中增加如下指令, 可在qweb的编译模板过程中进入断点语句,

〈t t-debug="随便什么东东" /> 

这时, 我们可以在控制台的源码页签中看到编译的中间过程,

在控制台下, 使用console.log(dict) 可以看到传入的所有参数

使用console.log(r) 可以看到输出中间结果

官方文档上 介绍的使用方法 〈t t-debug />  ,如果后面不随便添加些什么东东, 会出现如下错误

Specification mandate value for attribute t-debug

【5】模板文件示例  (在qweb目录下, 文件名为 laoliu.xml)

如下是官网上web文档中的例子, 增加了t-log和t-debug语句

〈templates>
〈div t-name="example_template" t-attf-class="base #{cls}">
〈t t-log="'in example_template, value of [items]:'" />
〈t t-log="items" />
〈h4 t-if="title"> 〈t t-esc="title"/> 〈/h4>
〈ul>
〈li t-foreach="items" t-as="item" t-att-class="item_parity">
〈t t-call="example_template.sub">
〈t t-set="arg" t-value="item_value"/>
〈/t>
〈/li>
〈/ul>
〈t t-debug="随便什么东东" />
〈/div> 〈t t-name="example_template.sub">
〈t t-log="'in example_template.sub, value of [arg]:'" />
〈t t-log="arg" />
〈t t-esc="arg.name"/>
〈dl>
〈t t-foreach="arg.tags" t-as="tag" t-if="tag_index lt 5">
〈dt> 〈t t-esc="tag"/> 〈/dt>
〈dd> 〈t t-esc="tag_value"/> 〈/dd>
〈/t>
〈/dl>
〈/t>
〈/templates>

【6】 程序示例  (在qweb目录下, 文件名为 laoliu.html)

访问方法:http://127.0.0.1:8069/web/static/lib/qweb/laoliu.html

〈!doctype html>
〈html>
〈head>
〈script src="../jquery/jquery-1.8.3.js"> 〈/script>
〈script type="text/javascript" src="qweb2.js"> 〈/script>
〈script>
var laoliu_data={
"class1": "foo",
"title": "Random Title",
"items": [
{ "name": "foo", "tags": {"bar": "baz", "qux": "quux"} },
{ "name": "Lorem", "tags": {
"ipsum": "dolor",
"sit": "amet",
"consectetur": "adipiscing",
"elit": "Sed",
"hendrerit": "ullamcorper",
"ante": "id",
"vestibulum": "Lorem",
"ipsum": "dolor",
"sit": "amet"
}
}
]
}; QWeb = new QWeb2.Engine();
QWeb.debug = true;
QWeb.add_template('laoliu.xml');
template='laoliu.xml';
result=QWeb.render('example_template', laoliu_data );
$(document).ready(function () {
$('.placeholder').append(result);
});
〈/script> 〈/head>
〈body>
〈div class="placeholder">
〈/div>
〈/body>
〈/html>

【7】t-debug的运行结果

(function(dict
) { var context = { engine : this, template : 'example_template' };
dict = dict || {};
dict['__template__'] = 'example_template';
var r = [];
r.push(' 〈div');
r.push(context.engine.tools.gen_attribute(['class', ('base ' + (dict['cls']))]));
r.push('> ',
'n ');
console.log('in example_template, value of [items]:');
r.push('n ');
console.log(dict['items']);
r.push('n ');
if (dict['title']) {
r.push(' 〈h4> ');
r.push(context.engine.tools.html_escape(dict['title']));
r.push(' 〈/h4> ');
}
r.push('n 〈ul> ',
'n ');
context.engine.tools.foreach(context, dict['items'], 'item', dict, function(context, dict) {
r.push(' 〈li');
r.push(context.engine.tools.gen_attribute(['class', (dict['item_parity'])]));
r.push('> ',
'n ');
r.push(context.engine.tools.call(context, 'example_template.sub', dict, '', function(context, dict) {
var r = [];
r.push('n ');
dict['arg'] = (dict['item_value']);
r.push('n ');
return r.join('');
}));
r.push('n 〈/li> ');
});
r.push('n 〈/ul> ',
'n ');
debugger;
r.push('n 〈/div> '); return r.join('');
})

openerp所用QWEB2的调试笔记的更多相关文章

  1. Tomcat调试笔记

    调试笔记 在使用Tomcat过程中经常碰到问题,导致tomcat启动失败.如下↓ 由于报错太过笼统,我根本无法找出错误.后来我切换到Console视图下,看到了如下错误信息. 根据报错信息,错误原因是 ...

  2. JavaScript特效(调试笔记)

    JavaScript特效 一.在网页上显示当前的时间日期,例如:“2016年3月26日 星期六”. js源代码: function getTime() { var today = new Date() ...

  3. USB wifi调试笔记

    本文以realtek 8192CU WiFi模块为例,介绍USB wifi在Jelly Bean 4.1的调试笔记. 1.WIFI打不开现象概述 WiFi打不开是指您在UI的settings下选中Wi ...

  4. ida动态调试笔记

    ida动态调试笔记 目标文件:阿里安全挑战赛的第二题 点击打开链接 使用环境:ida6.8点击打开链接,adt bundle点击打开链接 首先打开avd安卓模拟器,界面如下: 在dos下运行adb命令 ...

  5. modbus-poll和modbus-slave工具的学习使用——modbus协议功能码3的解析(及欧姆龙温控器调试笔记)

    最近的项目中使用到了欧姆龙的温控器,里面有很多的通信方式,我们使用的常见的modbus——RTU方式,其他方式我们不使用,其中通信手册上面有很多通信的实例,欧姆龙modbus还区分4字节模式和2字节模 ...

  6. GDB调试笔记

    参考资料:GDB调试精粹及使用实例 # 调试实例 #include <iostream> #include <cstring> using namespace std; ][] ...

  7. 《C#并行编程高级教程》第7章 VS2010任务调试 笔记

    没有什么好说的,主要是将调试模式下的Parallel Tasks窗体和Parallel Stacks窗体.折腾一下应该比看书效果好.(表示自己没有折腾过) 另外值得注意的是,主线程不是一个任务.所以主 ...

  8. SIM900A模块HTTP相关调试笔记

    SIM900A模块使用笔记 更新2018-12-8 正常工作状态: 接线方法: 首先将 AT 写入字符串输入框,然后点击 发送.因为模块波特率默认是 9600,所以两条指令的显示都是没有问题的:如果将 ...

  9. 博世传感器调试笔记(一)----加速度传感器BMA253

    公司是bosch的代理商,最近一段时间一直在公司开发的传感器demo板上调试bosch sensor器件.涉及到的器件有7,8款,类型包括重力加速度.地磁.陀螺仪.温度.湿度.大气压力传感器等.在调试 ...

随机推荐

  1. pytest学习(1)

    pytest是python的一个测试框架,主要是用来进行一些小的测试. 在pycharm中,缺省用的是unittest,这里说明如何设置为pytest. 当然,第一部是安装pytest pip3 in ...

  2. mysql查看每张表的空间使用情况

    use information_schema; /,),'MB') as data ,concat(round(index_length//,),'MB') as indexweight from T ...

  3. Cookie和session的简单理解和应用

    一.COOKIE 1.http协议建立连接后,无法保持状态:但实际情况,网站和服务器要进行通讯,需要“保持状态”,因此cookie应运而生:浏览器登陆web服务器后, Web 服务器产生包含有关用户的 ...

  4. [orangehrm] 安装问题集合

    Web server allows .htaccess files # 这一项检查不通过 解决: In conf/extra/httpd-vhosts.conf, add the line Allow ...

  5. 洛谷——P1407 工资

    P1407 工资 题目描述 有一家世界级大企业,他们经过调查,发现了一个奇特的现象,竟然在自己的公司里,有超过一半的雇员,他们的工资完全相同! 公布了这项调查结果后,众多老板对于这一现象很感兴趣,他们 ...

  6. [POJ1801]Formula Racing(模拟)

    Formula Racing Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 289   Accepted: 77 Descr ...

  7. [Codeforces 26E] MultiThreading

    Brief Intro: 给你n个数,每个数有2*CNT[i]个,让你构造一个序列 使得最终的Y值为W(其余见题面) Solution: 就是一道纯构造的题目: 先把特殊情况特殊处理,接下来考虑一般情 ...

  8. python3-开发面试题(python)6.22基础篇(1)

    1.为什么学习Python? 1.语言排行榜 2.语言本身简洁,优美,功能超级强大的 3.跨平台 4.非常火爆的社区 5.用的公司的多 2.通过什么途径学习的Python? 某宝2.8就搞定了,跟着视 ...

  9. elasticsearch将数据导出json文件【使用elasticdump】

    1.前提准备 需要使用npm安装,还未安装的朋友可以阅读另一篇我的博客<安装使用npm>,windows环境. 2.安装es-dump 打开终端窗口PowerShell或者cmd. 输入命 ...

  10. Problem Y: 零起点学算法21——摄氏温度转换

    #include<stdio.h> int main() { float f,c; while(scanf("%f",&f)!=EOF) c=*(f-); pr ...