[Django]-How to check if a field/attribute is null and blank in Django?

3👍

You can simply use {% if not order.payment %}, and I’m pretty sure you can also use {% if not order.payment.exists %}, or {% if order.payment is None %}

👤Hybrid

3👍

blank is not the state of a field. If a field is blank, then it means that no value is required to be passed. The for example a default value is used.

You can check if a value is NULL by checking if the value is None:

{% if order.payment is None %}
    …
{% endif %}

Leave a comment