【问题标题】:Django TemplateSyntaxError: Error during template renderingDjango TemplateSyntaxError:模板渲染期间出错
【发布时间】:2017-05-21 04:46:59
【问题描述】:

我正在开发一个 Python/Django 项目,之前并没有真正使用过。我目前在点击我网站上某个页面上的链接时收到TemplateSyntaxError

此链接将您带到的 URL(损坏页面的 URL)是:costing/id/payment-report/overview & 异常值显示:

第 87 行的块标记无效:“date_to_display”,预期为“elif”、“else”或“endif”。您是否忘记注册或加载此标签?

此页面的模板(HTML 文件)本身实际上并没有此变量。模板在文件夹结构中的位置是:costing/templates/costing/reports_post_deposit.html,但是在costing/pdf2_base.html 处还有另一个模板文件,它确实在结构中包含了这个变量:

<body>
    ...
    {% block content_payment_schedule %}
        {% if not webview %}
            <div>
                <table>
                    ...
                    <tr>
                        ...
                        <td> {% date_to_display %} </td>
                    </tr>
                </table>
            </div>
        {% endif %}
        ...
    {% endblock %}
    ...

</body>

所以我可以看到它所抱怨的变量在这个模板中被使用了。 costing/id/payment-report/overview 页面用于根据存储在数据库中的信息和用户提供的信息生成 PDF 文件。此 PDF 文件的结构在 costing/pdf2_base.html 文件中定义,date_to_display 是一个变量,我想将其值添加到生成的 PDF...

我需要做什么来注册或加载这个标签,因为错误消息说我需要做什么?

【问题讨论】:

  • 我想你可能打算 {{ date_to_display }}

标签: python django templates pdf tags


【解决方案1】:

在您使用的 django 模板中显示变量时

{{variable}}

以便解决您的问题更改

{% date_to_display %}

进入

{{date_to_display}}

【讨论】:

    【解决方案2】:

    您可以在以下链接中查看如何在 django 模板中显示变量; https://docs.djangoproject.com/en/1.10/topics/templates/#variables

    【讨论】:

      猜你喜欢
      • 2023-03-06
      • 1970-01-01
      • 1970-01-01
      • 2017-01-31
      • 2017-07-03
      • 1970-01-01
      • 2014-05-21
      • 1970-01-01
      • 2017-11-13
      相关资源
      最近更新 更多