首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >找不到Qweb模板- Odoo v8

找不到Qweb模板- Odoo v8
EN

Stack Overflow用户
提问于 2016-10-26 02:27:55
回答 1查看 1.6K关注 0票数 1

我正在用Odoo v8开发一个网站。我想编写一个代码片段,它的结构是由javascript加载的。贝娄是我的密码..。首先,我有一个代码片段结构:

代码语言:javascript
复制
<template id="snippet_hello" inherit_id="website2.snippets" name="Snippet Hello">
    <xpath expr="//div[@id='snippet_structure']" position="inside">
        <div class="oe_snippet">
            <div class="oe_snippet_thumbnail">
                <img class="oe_snippet_thumbnail_img" src="/path_to_block_icon/block_icon.png"/>
                <span class="oe_snippet_thumbnail_title">Hello</span>
            </div>
            <section class="oe_snippet_body">
                <div class="oe_snippet_hello">Hello ...</div>
            </section>
        </div>
    </xpath>
    <xpath expr="//div[@id='snippet_options']" position="inside">
        <div data-snippet-option-id='snippet_hello'
            data-selector=".oe_snippet_hello"
            data-selector-siblings="p, h1, h2, h3, blockquote, .well, .panel">
        </div>
    </xpath>
</template>

然后,我有一些javascript代码来呈现片段内容:

代码语言:javascript
复制
(function () {
    'use strict';
    var website = openerp.website;
    qweb = openerp.qweb;
    qweb.add_template('/path_to_snippet_qweb_template/snippet_template_filename.xml');

    website.snippet.animationRegistry.hello = website.snippet.Animation.extend({
        selector: ".oe_snippet_hello",
        start: function(){
            var $content = $(qweb.render('website.snippet_hello', {a:1}));
            $content.appendTo(this.$target);
        },
    });

})();

然后,我有一个QWeb模板来显示结构内容(filename: snippet_template_filename.xml):

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
<templates id="template" xml:space="preserve">
    <t t-name="website.snippet_hello">
        <div contenteditable="false">
            <p>Hello snippet</p>
            <t t-esc="a"/>
        </div>
    </t>
</templates>

问题是这条线:

代码语言:javascript
复制
var $content = $(qweb.render('website.snippet_hello', {a:1}));

发生了“模板'website.snippet_hello‘找不到”的错误,我注意到当我作为Admin登录时(还没有尝试其他帐户),它工作得很好。当我在浏览器上登录时,它只是发生了错误。请让我听听你的建议,谢谢!

EN

回答 1

Stack Overflow用户

发布于 2020-07-03 05:44:20

这是一个与过时的Odoo版本有关的老问题,但今天的答案仍然适用(Odoo 11/12/13):

Template Not found可能在下列情况下发生:

  • 模板未加载
  • 模板名称在js和模板的xml文件之间并不相等。模板名称区分大小写。

加载模板:

通常,您在项目中将模板保存为/your_module/static/src/xml/snippet_template_filename.xml,并且必须通过添加以下内容在/your_module/__manifest__.py上加载此xml文件:

代码语言:javascript
复制
 'qweb': [
        "static/src/xml/snippet_template_filename.xml",
    ],

或速记:

代码语言:javascript
复制
 'qweb': [
        "static/src/xml/*.xml",
    ],

您可以在odoo的App菜单中安装/更新your_module,然后可以通过查看http://localhost:8069/web/webclient/qweb?mods=your_module来验证您的模板是否加载,它应该会返回模板。

您还可以查看“最喜欢的浏览器网络检查器”来检查http://localhost:8069/web/webclient/qweb?mods=[...]请求,并检查mods中是否正确加载了your_module

模板可以在js中使用,如下所示(Odoo >= v11):

代码语言:javascript
复制
odoo.define('your_module.NameOfYourJs', function (require) {
    "use strict";
    var QWeb = core.qweb;
    [...]
    var result = QWeb.render('website.snippet_hello', {a:1});

});

注意:要调试资产,可以使用http://localhost:8069/web?debug=assets

希望这能有所帮助!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40252744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档