What is the equivalent of “none” in django templates?

后端 未结 7 936
孤街浪徒
孤街浪徒 2020-12-12 21:40

I want to see if a field/variable is none within a Django template. What is the correct syntax for that?

This is what I currently have:

{% if profile         


        
7条回答
  •  囚心锁ツ
    2020-12-12 22:08

    You could try this:

    {% if not profile.user.first_name.value %}
      

    --

    {% else %} {{ profile.user.first_name }} {{ profile.user.last_name }} {% endif %}

    This way, you're essentially checking to see if the form field first_name has any value associated with it. See {{ field.value }} in Looping over the form's fields in Django Documentation.

    I'm using Django 3.0.

提交回复
热议问题