简体   繁体   English

Django TemplateSyntaxError:模板渲染期间发生错误

[英]Django TemplateSyntaxError: Error during template rendering

I am working on a Python/ Django project, having not really used either much before. 我正在研究Python / Django项目,之前从未真正使用过。 I am currently getting a TemplateSyntaxError when clicking a link on one of the pages on my website. 单击我网站上页面之一上的链接时,我当前收到TemplateSyntaxError

The URL that this link takes you to (the URL for the broken page) is: costing/id/payment-report/overview & the exception value says: 该链接将您带到的URL(断开页面的URL)为: costing/id/payment-report/overview ,并且异常值显示为:

Invalid block tag on line 87: 'date_to_display', expected 'elif', 'else' or 'endif'. 第87行的无效代码块:“ date_to_display”,预期的“ elif”,“ else”或“ endif”。 Did you forget to register or load this tag? 您是否忘记注册或加载此标签?

The template (HTML file) itself for this page, doesn't actually have this variable anywhere in it. 此页面的模板(HTML文件)本身实际上在任何地方都没有此变量。 The location of the template in the folder structure is: costing/templates/costing/reports_post_deposit.html , however, there is another template file at costing/pdf2_base.html , which does contain this variable within the structure: 模板在文件夹结构中的位置为: 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>

So I can see that the variable it's complaining about is used within this template. 因此,我可以看到它抱怨的变量已在此模板中使用。 The page at costing/id/payment-report/overview is used to generate a PDF file from information stored in the database, and information provided by the user. costing/id/payment-report/overview用于从数据库中存储的信息以及用户提供的信息生成PDF文件。 The structure of this PDF file is defined in the costing/pdf2_base.html file- and date_to_display is aa variable whose value I wanted to add to the PDF generated... 此PDF文件的结构在costing/pdf2_base.html文件中定义,并且date_to_display是一个变量,我想将其值添加到生成的PDF中...

What do I need to do to register or load this tag, as the error message says I need to do? 错误消息提示我需要注册或加载此标签,我该怎么做?

when displaying a variable in django templates you use 在Django模板中显示变量时使用

{{variable}}

so to fix your issue change 以便解决您的问题更改

{% date_to_display %}

into 进入

{{date_to_display}}

You can check how to display variables in django template in the following link; 您可以在以下链接中查看如何在django模板中显示变量; https://docs.djangoproject.com/en/1.10/topics/templates/#variables https://docs.djangoproject.com/en/1.10/topics/templates/#variables

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM