Django — Template tag in {% if %} block

前端 未结 4 367
花落未央
花落未央 2020-12-16 08:51

I have the following dictionary passed to a render function, with sources being a list of strings and title being a string potentially equal to one of the strings in sources

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-16 09:45

    {% for source in sources %}
      
        {{ source }}
        
          {% ifequal title source %}
            Just now!
          {% endifequal %}
        
      
    {% endfor %}
    
                    or
    
    
    {% for source in sources %}
          
            {{ source }}
            
              {% if title == source %}
                Just now!
              {% endif %}
            
          
        {% endfor %}
    

    See Django Doc

提交回复
热议问题