在 base.html 中:
<div id="menu_shop">
<input name="search" placeholder="search">
<p>Category:</p>
{% load mptt_tags %}
<ul class="root">
{% recursetree nodes %}
<li>
{{ node.name }}
{% if not node.is_leaf_node %}
<ul class="children">
{{ children }}
</ul>
{% endif %}
</li>
{% endrecursetree %}
</ul>
</div>
在意见中:
def show_category_tree(request):
return render_to_response("base.html",
{'nodes': Category.tree.all()},
context_instance=RequestContext(request))
网址.py:
url(r'^category/', 'item.views.show_category_tree'),
url(r'^category/(?P<slug>[\w\-_]+)/$', 'item.views.by_category'),
如何在“by_category.html”中显示它
如果我尝试(例如):
{% extends "base.html" %}
{% block content %}
{% for e in entries %}
<p><b>{{ e.name}}</b></p>
<p>{{ e.desc}}</p>
{% endfor %}
{% endblock %}
我有这个错误:
{% extends "base.html" %} 不起作用。如果我删除它,一切正常。