Django TemplateSyntaxError:模板呈现时出错 [英] Django TemplateSyntaxError: Error during template rendering
问题描述
我正在使用Python / Django项目,之前并没有真正使用过。当我点击网站上某个页面上的一个链接时,我正在收到一个 TemplateSyntaxError
。
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.
此链接带您到(破碎的页面的URL)是: costing / id / payment-report / overview
&异常值说:
The URL that this link takes you to (the URL for the broken page) is: costing/id/payment-report/overview
& the exception value says:
第87行上的无效块标记:'date_to_display',预期'elif','else'或'endif' 。您是否忘记注册或加载此标签?
Invalid block tag on line 87: 'date_to_display', expected 'elif', 'else' or 'endif'. Did you forget to register or load this tag?
此页面的模板(HTML文件)本身并不具有此变量在任何地方。模板在文件夹结构中的位置是: costing / templates / costing / reports_post_deposit.html
,但是,另一个模板文件位于 pdf2_base.html
,它在结构中包含此变量:
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>
所以我可以看到这个模板中使用了它所抱怨的变量。 costing / id / payment-report / overview
中的页面用于从存储在数据库中的信息和用户提供的信息生成PDF文件。该PDF文件的结构在 costing / pdf2_base.html
文件中定义,而 date_to_display
是一个变量,其值我想添加到PDF生成...
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...
我需要做什么来注册或加载这个标签,错误消息说我需要做什么? / p>
What do I need to do to register or load this tag, as the error message says I need to do?
推荐答案
在您使用的django模板中显示变量
when displaying a variable in django templates you use
{{variable}}
所以要解决你的问题变化
so to fix your issue change
{% date_to_display %}
into
{{date_to_display}}
这篇关于Django TemplateSyntaxError:模板呈现时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!