Cannot parse data into {% include %} tag - Django

问题描述 投票:0回答:0

我在templates/forum目录中有forum.html模板

<div style="height:50px; width:100%">welcome to forum {{ obj.forum_name }}</div>

我想将此模板包含到我的 topic.html 模板中,该模板位于同一目录中。我想使用with

传递数据
{% include 'forum/forum.html' with obj.forum_name="windmaker" %}

但是它没有按预期工作。它给了我

"with" in 'include' tag needs at least one keyword argument.

错误。

我能做什么?

据我所知,问题是由点 (.) 运算符引起的。我试着不使用它,突然它正确地呈现了页面

我在这里摆脱

.forum_name
里面
forum.html

<div style="height:50px; width:100%">welco to forum {{ obj }}</div>

这里我在里面传递了数据

topic.html

{% include 'forum/forum.html' with obj="windmaker" %}

突然间它起作用了!

django include
© www.soinside.com 2019 - 2024. All rights reserved.