Templates

Generating HTML in Python isn't very pleasant.

The usual solution istemplates, pseudo-documents with placeholders and display logic. Odoo allows any Python templating system, but provides its ownQWebtemplating system which integrates with other features.

Create a template and ensure the template file is registered in the__manifest__.pymanifest, and alter the controller to use our template:

academy/controllers.py

class Academy(http.Controller):
    @http.route('/academy/academy/', auth='public')
    def index(self, **kw):
        return http.request.render('academy.index', {
            'teachers': ["Diana Padilla", "Jody Caroll", "Lester Vaughn"],
        })

#     @http.route('/academy/academy/objects/', auth='public')
#     def list(self, **kw):

academy/templates.xml

<odoo>
    <data>
        <template id="index">
            <title>Academy</title>
            <t t-foreach="teachers" t-as="teacher">
              <p><t t-esc="teacher"/></p>
            </t>
        </template>
        <!-- <template id="object"> -->
        <!--   <h1><t t-esc="object.display_name"/></h1> -->
        <!--   <dl> -->

The templates iterates (t-foreach) on all the teachers (passed through thetemplate context), and prints each teacher in its own paragraph.

Finally restart Odoo and update the module's data (to install the template) by going toSettings ‣ Modules ‣ Modules ‣ Academyand clickingUpgrade.

Tip

Alternatively, Odoo can be restartedand update modules at the same time:

$ odoo-bin --addons-path addons,my-modules -d academy -u academy

Going tohttp://localhost:8069/academy/academy/should now result in:

results matching ""

    No results matching ""