<p>不能直接调用django模板引擎中的函数。您可以使用django模板过滤器来实现这一点。这样试试</p>
<pre><code>from django import template
register = template.Library()
@register.filter
def my_points(idemployee):
answer_query = answers.objects.select_related(
'question').filter(empleado=idemployee)
points_total = 0
match = 0
for answer in answer_query:
if answer.question.golesEquipoA == answer.equipoA and answer.question.golesEquipoB == answer.equipoB:
points_total += 4
match += 1
else:
if answer.question.golesEquipoA == answer.question.golesEquipoB and answer.equipoA == answer.equipoB:
points_total += 3
match += 1
else:
if answer.question.golesEquipoA < answer.question.golesEquipoB and answer.equipoA < answer.equipoB:
points_total += 3
match += 1
if answer.question.golesEquipoA > answer.question.golesEquipoB and answer.equipoA > answer.equipoB:
points_total += 3
match += 1
args = {}
args['points'] = points_total
args['match'] = match
return args
</code></pre>
<p><a href="https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters" rel="nofollow">https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#writing-custom-template-filters</a></p>