从Django应用程序加载templatetags时出错

时间:2017-01-18 20:51:46

标签: python django django-templates django-tagging

我正在尝试加载django-tagging应用程序中包含的模板标记(django-tagging templatetags docs不指定load语句应该是什么)但是我收到了TemplateSyntax错误提醒我加载或注册标签 - 我很确定我已经完成了。

这是我模板的相关部分

def _verify_integrity(self, labels=None, levels=None):
    """

    Parameters
    ----------
    labels : optional list
        Labels to check for validity. Defaults to current labels.
    levels : optional list
        Levels to check for validity. Defaults to current levels.

    Raises
    ------
    ValueError
        * if length of levels and labels don't match or any label would
        exceed level bounds
    """
    # NOTE: Currently does not check, among other things, that cached
    # nlevels matches nor that sortorder matches actually sortorder.
    labels = labels or self.labels
    levels = levels or self.levels

    if len(levels) != len(labels):
        raise ValueError("Length of levels and labels must match. NOTE:"
                         " this index is in an inconsistent state.")
    label_length = len(self.labels[0])
    for i, (level, label) in enumerate(zip(levels, labels)):
        if len(label) != label_length:
            raise ValueError("Unequal label lengths: %s" %
                             ([len(lab) for lab in labels]))
        if len(label) and label.max() >= len(level):
            raise ValueError("On level %d, label max (%d) >= length of"
                             " level  (%d). NOTE: this index is in an"
                             " inconsistent state" % (i, label.max(),
                                                      len(level)))

错误消息是:

  

第11行的无效块标记:'tags_for_model',预期'endblock'。   您是否忘记注册或加载此标记?

查看django-tagging模块,我可以看到templatetags代码:

1   {% extends "base_tags.html" %}
2   
3   {% load staticfiles %}
4   {% load coltrane_tags %}
5   {% load tagging_tags %)
6   
7   <div class="row">
8   
9     {% block content %}
10    <div class="col-md-9">
11      {% tags_for_model coltrane.Entry as entry_tags %}
12      {% for obj in entry_tags %}
13        {{ obj }}
14      {% endfor %}
..    </div>
..    {% endblock %}
..  </div>            

我要使用的标签已在此文件中注册:

<PythonVirtualEnv>/site-packages/tagging/templatetags/tagging_tags.py

所以从我的角度来看,它既已注册又已加载 - 是否有任何明显的遗漏?

0 个答案:

没有答案