Django和Mustache的模板使用相同的语法 [英] Django and Mustache use the same syntax for template

查看:145
本文介绍了Django和Mustache的模板使用相同的语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试将HTML模板中的HTML模板走私到mustache.js, django模板引擎删除所有应为 照原样输出到前端

I try to smuggle HTML template in the HTML for mustache.js, however the django template engine remove all the placeholders that should be output as-is to the front-end

模板通过以下方式包含在HTML中:

The template is included in HTML in this way:

<script type="text/x-mustache-template" data-id="header_user_info">
    <div id="header_user_info">
        <div id="notification">0</div>
        <a href="#">{{username}}</a>
    </div>
</script>

,我可以通过运行$(el).html()来获取HTML模板,并生成 html,方法是使用Mustache.to_html(temp,data);

and I can get the HTML template by running $(el).html(), and generate html by using Mustache.to_html(temp, data);

我可以将所有模板放入另一个静态文件中,并从 CDN,但是很难跟踪模板的位置, 以及至少一个额外的http请求.

I could put all the template into another static file and serve from CDN, but then it would be hard to track where the template belongs, and at least one extra http request.

推荐答案

您可以使用{% templatetag %} templatetag打印通常由Django处理的字符.例如:

You can use the {% templatetag %} templatetag to print out characters that would normally be processed by Django. For example:

{% templatetag openvariable %} variable {% templatetag closevariable %}

在您的HTML中显示以下内容:

Results in the following in your HTML:

{{ variable }}

有关参数的完整列表,请参见: https://docs .djangoproject.com/en/dev/ref/templates/builtins/#templatetag

For a full list of arguments see: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#templatetag

这篇关于Django和Mustache的模板使用相同的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆