其餘內的HTML我試圖執行雙重的,其中第二個從父親繼承的數據,如下:無法解析在Django {%for子句
{% for category in categories %}
<li><a href="/categories/{{ category.id }}/">{{ category.name }}</a>
{% for cat in category.objects.filter(parent=category.id) %}
{% if forloop.first %}
<ul class="noJS">
{% endif %}
<li><a href="/categories/{{ cat.id }}">{{cat.name}}</a></li>
</ul>
{% endfor %}
{% endfor %}
的問題是,我得到錯誤:
TemplateSyntaxError at/
Could not parse the remainder: '(parent=category.id))' from 'ca
tegory.objects.filter(parent=category.id))'
Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.3
Exception Type: TemplateSyntaxError
Exception Value:
Could not parse the remainder: '(parent=category.id))' from 'category.objects.filter(parent=category.id))'
任何想法?
這是錯的!你正在循環相同的模型? – catherine 2013-04-06 13:56:32
我的模型繼承自身,就像樹 – Walucas 2013-04-06 13:59:17
也許你應該嘗試另一種方式,而不是在模板內部過濾它 – catherine 2013-04-06 14:05:58