###前提・実現したいこと
モデルに登録した値の大きさごとに色を変えたい。
###該当のソースコード
scoreに登録された値が0〜50なら青、51〜80ならオレンジ、81〜100なら赤でscore変数の値を表示させたい。
models.pyに
class TestScore(models.Model): score = models.IntegerField(max_length=100, null=True)
views.pyに
def test_result(request): test_score = TestScore.objects.all() return render(request, 'detail.html', {'test_score': test_score})
htmlに
<div class="col-sm-8"> {% for score in test_score.all %} <h4> {{ score.score }}</h4> {% endfor %} </div>
と書いた。
###試したこと
if-else文で、0〜50なら青、51〜80ならオレンジ、81〜100なら赤で表示するというものを書こうとしたが、htmlにどう書けばいいのかわからなかった。
jQueryでそのように値により色を変える方法を見つけ、自分はhtmlだけでできると思っていたが、jQueryなどを使う必要があるのかもしれないとも思った。http://y0m0r.hateblo.jp/entry/20120621/1340291543
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。