Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用 django 1.5,我需要检查是否定义了变量(如果定义了变量但没有,0,“”等......)。就像是:
{% ifexists a_variable %} <p> Hey the variable exists </p> {% endifexists %}
我不知道如何最好地做到这一点......
请阅读文档。
{% if %} 标签评估一个变量,如果该变量为“真”(即存在......
{% if athlete_list %} Number of athletes: {{ athlete_list|length }} {% elif athlete_in_locker_room_list %} Athletes should be out of the locker room soon! {% else %} No athletes. {% endif %}
您可能还想查看相当方便的 Django编写公共视图的教程。