【问题标题】:My app does not show if statement in browser我的应用程序未在浏览器中显示 if 语句
【发布时间】:2017-02-25 06:16:18
【问题描述】:

我的应用程序没有在浏览器中显示 if 语句。 我写在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>

我想在我的应用的浏览器中显示, 如果用户的分数大于 5000,我想在我的浏览器中显示“Good”,而用户的分数小于 900,我想在我的浏览器中显示“Bad”。 但是现在,我所有的 if 语句都显示在我的应用程序的浏览器中。 数据库有用户的tcresults数据。 我应该如何解决这个问题?

【问题讨论】:

    标签: python html django


    【解决方案1】:

    在 Django 模板中,条件和循环写在{% conditions/loops %}

    虽然变量写在{{ variables }}

    文档https://docs.djangoproject.com/en/1.10/ref/templates/builtins/#if

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

    【讨论】:

      猜你喜欢
      • 2023-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-19
      • 2014-04-11
      • 1970-01-01
      • 2013-10-23
      相关资源
      最近更新 更多