Hello World! with a QWeb template

Using Python strings to build HTML will get boring very fast. QWeb templates does a much better job. So, let's write an improved version of our Hello World web page, using a template.

QWeb templates are added through XML data files, and technically they are just a type of view, alongside form or tree views. They are even stored in the same technical Model, ir.ui.view.

As usual, data files to be loaded must be declared in the manifest file, so edit the todo_website/__manifest__.py file to add the key:

'data': ['views/todo_web.xml'], 

Then, add the actual data file, views/todo_web.xml, with the following content:

<odoo> <template id="hello" name="Hello Template"> <h1>Hello World !</h1> </template> </odoo>  ...

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.