Django TemplateSyntaxError: Error during template rendering

☆樱花仙子☆ 提交于 2020-01-07 02:37:07

问题


I am working on a Python/ Django project, having not really used either much before. I am currently getting a TemplateSyntaxError when clicking a link on one of the pages on my website.

The URL that this link takes you to (the URL for the broken page) is: costing/id/payment-report/overview & the exception value says:

Invalid block tag on line 87: 'date_to_display', expected 'elif', 'else' or '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. 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:

<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. The structure of this PDF file is defined in the costing/pdf2_base.html file- and date_to_display is a a variable whose value I wanted to add to the PDF generated...

What do I need to do to register or load this tag, as the error message says I need to do?


回答1:


when displaying a variable in django templates you use

{{variable}}

so to fix your issue change

{% date_to_display %}

into

{{date_to_display}}



回答2:


You can check how to display variables in django template in the following link; https://docs.djangoproject.com/en/1.10/topics/templates/#variables



来源:https://stackoverflow.com/questions/41505414/django-templatesyntaxerror-error-during-template-rendering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!