【发布时间】:2018-03-03 00:11:28
【问题描述】:
我试图在 django 模板上调用 python 视图方法 res() 但它没有被调用。
这是我的观点
class make_incrementor(object):
def __init__(self, start):
self.count=start
def __call__(self, jump=1):
self.count += jump
return self.count
@property
def res(self):
self.count =0
return self.count
def EditSchemeDefinition(request, scheme_id):
iterator_subtopic = make_incrementor(0)
scheme_recs = scheme.objects.get(id=scheme_id)
view_val = {
'iterator_subtopic': iterator_subtopic,
"scheme_recs": scheme_recs,
}
return render(request, "edit.html", view_val)
我正在尝试增加计数,然后在一个级别之后将其重置为 0 但是它的重置方法没有从 Django 模板中获得调用。
这是我的 edit.html 页面
<td id="subTopic" class="subTopic">
{% for strand in scheme_recs.stand_ids.all %}
{{ iterator_subtopic.res }}
{% for sub_strand in strand.sub_strand_ids.all %}
{% for topic in sub_strand.topic_ids.all %}
{% for subtopic in topic.sub_topic_ids.all %}
<input id="subTopic{{ iterator_subtopic }}" class="len"
value="{{ subtopic.name }}">
<br>
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}
</td>
我的 {{ iterator_subtopic.res }} 没有得到调用,并且 iterator_subtopic 的值没有再次设置为 0。函数及其调用在终端上运行良好,但在 django 模板中无法呈现。
请纠正我做错的地方。 提前致谢。
【问题讨论】:
标签: html django python-2.7