Lektor分页 - TemplateSyntaxError:遇到未知标签'endblock'

时间:2016-03-02 16:38:44

标签: python pagination jinja2 static-site lektor

使用Lektor,我创建了一个模型book作为books模型的子项(类似于blog-post& blog模型)。

/books/页面正确生成,底部有分页。当我转到第二页时,它会抛出这个奇怪的错误。

Build Failure :'(

Building of the artifact “books/page/2/index.html” failed. This is what we know about the problem:

Traceback (most recent call last):
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/lektor/builder.py", line 702, in update
    yield ctx
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/lektor/builder.py", line 924, in build_artifact
    build_func(artifact)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/lektor/build_programs.py", line 169, in build_artifact
    self.source['_template'], this=self.source)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/lektor/builder.py", line 592, in render_template_into
    this=this, **extra)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/lektor/environment.py", line 466, in render_template
    return self.jinja_env.get_or_select_template(name).render(ctx)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/jinja2/environment.py", line 851, in get_or_select_template
    return self.get_template(template_name_or_list, parent, globals)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/jinja2/environment.py", line 812, in get_template
    return self._load_template(name, self.make_globals(globals))
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/lektor/environment.py", line 194, in _load_template
    rv = jinja2.Environment._load_template(self, name, globals)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/jinja2/environment.py", line 786, in _load_template
    template = self.loader.load(self, name, globals)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/jinja2/loaders.py", line 125, in load
    code = environment.compile(source, name, filename)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/jinja2/environment.py", line 565, in compile
    self.handle_exception(exc_info, source_hint=source_hint)
  File "/home/anand/.virtualenvs/exp/lib/python2.7/site-packages/jinja2/environment.py", line 754, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/anand/projects/python/projectchalam/templates/books.html", line 13, in template
    {% endblock %}
TemplateSyntaxError: Encountered unknown tag 'endblock'.    

这是books.html

{% extends "base.html" %}

{% from "macros/pagination.html" import render_pagination %}

{% block title %}Books{% endblock %}


{% block content %}

    <ul class="blog-index">
        {% for post in this.pagination.items %}
            <h2>
                <a href="{{ post|url }}">
                    {{ post.title }}
                </a>
            </h2>
        {% endfor %}
    </ul>

    <div style="padding-left: 45px;">
        {% if this.pagination.pages > 1 %}
            {{ render_pagination(this.pagination) }}
        {% endif %}
    </div>
{% endblock %}

我在books.html第13行中没有{% endblock %},如追溯中所示。

1 个答案:

答案 0 :(得分:2)

如果您正在使用Lektor 1(当前发布的版本),语法错误有时会被缓存。清除lektor缓存以查看是否能解决问题(您可以使用lektor clean执行此操作。