【问题标题】:How to write something with a mustache in Django如何在 Django 中用小胡子写一些东西
【发布时间】:2020-07-06 10:57:33
【问题描述】:

我正在尝试使用 Django 技术实现一个带有 AMP 的网站,一切都很好,只是我想在不加载整个页面的情况下进行更改分页,所以我需要使用 amp-list,问题是当我开始使用它时我有问题。 我将稍微解释一下 amp-list,要使用 amp-list 获取数据,我们需要使用一些标签,例如 Django 上存在的标签,如 {{#posts}} 和 {{slug}},所以 Django 认为的问题这些是变量。

一个小例子:

<amp-list width="auto" height="100" layout="fixed-height" src="myUrl" [src]="myUrl + pageNumber">
   <template type="amp-mustache">
       {{#posts}}
        <div>
            <h1>{{title}}</h1>
            <p>{{content}}</p>
        </div>
        {{/posts}}
    </template>
</amp-list>

我尝试了一些方法,比如将它们放在一个变量中并在模板上调用它,但我得到了同样的错误。我想知道是否有一种方法可以使用这些标签,我想有一些东西可以让你在 Django 模板中写下 mustache。

【问题讨论】:

    标签: django django-templates


    【解决方案1】:

    您可以使用{% verbatim %}…{% endverbatim %} template block [Django-doc] 来禁用解释标记,例如{{}}

    如果您因此想要解释{{#posts}}{{title}} 等部分,那么您可以用verbatim 块包围它:

    {% verbatim %}
    <amp-list width="auto" height="100" layout="fixed-height" src="myUrl" [src]="myUrl + pageNumber">
       <template type="amp-mustache">
           {{#posts}}
            <div>
                <h1>{{title}}</h1>
                <p>{{content}}</p>
            </div>
            {{/posts}}
        </template>
    </amp-list>
    {% endverbatim %}

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-04-03
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-16
      相关资源
      最近更新 更多