Djangoのテンプレートで、if文の使い方をメモします。
views.py
from django.http import HttpResponse
from django.shortcuts import render
def index(request):
param_dict = {'param1': 'パラメータ1'}
return render(request, 'index.html', param_dict)
ビューではparam1のデータを送ります。
そのデータの存在チェックをテンプレートでif文で下記のように行っています。
テンプレート index.html
<!DOCTYPE html>
<html>
<head>
<title>タイトル</title>
</head>
<body>
{% if param1 %}
param1は存在します
{% endif %}
{% if param2 %}
param2は存在します
{% endif %}
</body>
</html>
index.htmlの表示結果

if文で、変数の存在チェックをして表示ができました。
param1のみ存在しているので、そちらだけif文で判断して表示できてます。
