Mustache.js 在 Django 模板中不起作用

Mustache.js within Django template not working

我想 render ajax 响应 Mustache.js 但由于某些原因,模板中的变量没有显示。我修改了 Mustache 的分隔符,但它仍然无法正常工作。

.js

/*
 * Get reservation preview snippet.
 */

$(document).ready(function() {
    Mustache.tags = ['<%', '%>'];
    var tableRows = $("#table-wrapper table tr");

    // table row was clicked
    tableRows.click(function(e) {
        e.preventDefault();

        var $this = $(this);
        var previewURL = $(this).find("#ajax_id").attr('data-id');

        // get preview and load it to template
        $.getJSON(previewURL, function(reservation) {
            console.log("Updated at: " + reservation.updated_at);
            var template = $('#reservationPreviewTpl').html();
            var html = Mustache.render(template, reservation);
            console.log('HTML' + html);
            $('#test123').html(html);
        });

    });

template

<div id="test123"></div>
<script id="reservationPreviewTpl" type="text/template">
<h1>I am a template</h1>
<p><% reservation.updated_at %></p>
</script>

Console output

原来 reservation.updated_at 应该只是 updated_at

template

<div id="test123"></div>
<script id="reservationPreviewTpl" type="text/template">
<h1>I am a template</h1>
<p><% updated_at %></p>
</script>