/ accounts / tcresults的AssertionError

时间:2017-02-25 07:22:03

标签: python html django

我收到了一个错误, / accounts / tcresults的AssertionError 没有提供异常消息。 我在tc.html中写道

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Score</title>
</head>
<body>
    <h1>Score</h1>
    <h2>Your Score is
     {{ tcresults.tc }}
      {{ value1 = tcresults.tc
         if value1 > 5000:
         <h2>Good</h2>
         elseif value1 < 900:
          <h2>Bad</h2>
       }}

    </h2>
</body>
</html>
在views.py中

def tc(request):
    tcresults = ImageAndUser.objects.filter(user=request.user).order_by('id').last()
    d = {
        'tcresults': tcresults,
    }
    return render(request, 'registration/accounts/tc.html', d)

我无法理解为什么会发生这种错误。 我该怎么做才能解决这个问题?

1 个答案:

答案 0 :(得分:0)

在你的HTML中,你应该这样做:

<h2>Your score is {{ tcresults.tc }}</h2>
{% if tcresults.tc > 5000 %}
    <h2>Good</h2>
{% elif tcresults.tc < 900 %}
    <h2>Bad</h2>
{% endif %}

{{ }}用于评估变量,而{% %}用于流量控制。