使用Django进行下划线/骨干模板化

时间:2012-10-12 10:52:20

标签: javascript django templates backbone.js underscore.js

中定义我的javascript模板时
<script type="text/template">
</script>

在我的Django应用程序中,它们不会在html中呈现(我在页面中看不到它们)。也许我声明的其中一个过滤器/中间件正在选择它们?

这来自settings.py

COMPRESS_PRECOMPILERS = (
    ('text/less', 'lessc {infile} {outfile}'),
)
if DEBUG:
    COMPRESS_REBUILD_TIMEOUT = 1

TEMPLATE_CONTEXT_PROCESSORS = (
     "django.core.context_processors.request",
     "django.contrib.auth.context_processors.auth",
     "django.core.context_processors.debug",
     "django.core.context_processors.i18n",
     "django.core.context_processors.media",
     "django.core.context_processors.static",
     "django.core.context_processors.tz",
     "django.contrib.messages.context_processors.messages",
)


MIDDLEWARE_CLASSES = (
    'django.middleware.common.CommonMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.middleware.transaction.TransactionMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'debug_toolbar.middleware.DebugToolbarMiddleware',
    # Uncomment the next line for simple clickjacking protection:
    # 'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

如果是这样,如何解决这个问题?

修改 模板:

<script type="text/template" id="new-catalog-template">

    <div class="catalog" data-id="<%= responseJSON.catalog.id %>" style="display: none">
        <div class="catalog-main-content">
            <div class="preview"><img src="<%= responseJSON.user_dir %>/catalogs/<%= responseJSON.catalog.id %>/ipad-preview-icon-large.png" alt="" /></div>
            <div class="name"><%= responseJSON.catalog.name %></div>
            <div class="last-build"><em>Last build:</em><%= responseJSON.catalog.last_build_natural %> (<%= responseJSON.catalog.last_build %>)</div>
            <div class="description"><%= responseJSON.catalog.description %></div>
        </div>
    </div>

</script>

**编辑编辑**

我的不好,脚本标签在主要区域之外,因此没有呈现¬_¬...顺便让我告诉我有关{{ verbatim }}的信息

1 个答案:

答案 0 :(得分:2)

我能看到那个模板吗?

如果没有 - 也许您可以使用escapejs-Filter或更好的新verbatim代码。