【问题标题】:AssertionError at /accounts/tcresults/accounts/tcresults 处的 AssertionError
【发布时间】:2017-02-25 07:22:03
【问题描述】:

我遇到了一个错误, /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)

我不明白为什么会发生这个错误。 我应该怎么做才能解决这个问题?

【问题讨论】:

    标签: python html django


    【解决方案1】:

    在您的 html 中,您应该这样做:

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

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

    【讨论】:

    • 谢谢,你的cmets。我写了你的代码,但是“你的分数是”的数字变成了空白。我该怎么办?
    • thx!!Your score is ~的部分显示出来了,但是if语句(包括Good & Bad)没有显示出来。我应该怎么做才能解决这个问题?
    • 可能tcresults.tc的值在900到5000之间。
    猜你喜欢
    • 2019-12-15
    • 2018-03-08
    • 2015-06-09
    • 2021-12-21
    • 1970-01-01
    • 2016-06-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多