我正在尝试使用django无限分页,但我收到了这个错误:
TemplateSyntaxError at /
u'paginate' tag requires a variable name `as` argumnent if the queryset is provided as a nested context variable (prodmatrix.items). You must either pass a direct queryset (e.g. taking advantage of the `with` template tag) or provide a new variable name to store the resulting queryset (e.g. `paginate prodmatrix.items as objects`).
这是我的模板:
{% load endless %}
**{% paginate prodmatrix.items %}**
{% for key, values in prodmatrix.items %}
<li class="span3">
<div class="product-box">
<span class="sale_tag"></span>
<p><a href="{% url 'product_detail' slug=values.3.0 %}"><img src="{{ STATIC_URL }}{{values.1.0}}" alt="" /></a></p>
<a href="{% url 'product_detail' slug=values.3.0 %}" class="title"><h4>{{ values.0.0 }}</h4></a><br/>
<p class="category"><a href="{% url 'product_detail' slug=values.3.0 %}">{{values.2.0}} {{values.2.1}} {{values.2.2}}</a></p> </div>
</li>
{% endfor %}
{% show_pages %}
这是我的观点:
def home(request):
if request.user.is_authenticated():
print "login"
user = request.user
prods = Product.objects.all()
i = 0
print 'numero de produtos ' + str(len(prods))
prodmatrix = {}
for prod in prods:
# 0 1 2 3
prodmatrix[str(i)] = [[prod.name], [prod.image], [], [prod.slug]]
reviews = Review.objects.filter(product=prod.id) # ^ this is for tags
print str(len(reviews))
if len(reviews) != 0:
for review in reviews:
rev_alltags = review.tag.all()
for tags in rev_alltags[:3]: #
print tags.name
prodmatrix[str(i)][2].append(tags.name) # append only tags
print str(i)
i = i + 1
return render(request, 'home.html',{'prodmatrix':prodmatrix})
答案 0 :(得分:1)
发生此错误是因为您未向模板传递任何名为条目的变量。
我不太了解lib提供解决方案,但我相信你需要做一些事情:
{% paginate prodmatrix.items %}