代码之家  ›  专栏  ›  技术社区  ›  panchicore

这个django模板if标记会发生什么?

  •  0
  • panchicore  · 技术社区  · 16 年前

    对不起,如果我是个白痴,那么这个if标签会发生什么呢?

    return render_to_response('productos/por_estado.html', {'productos':productos}, 
                       context_instance=RequestContext(request))
    #Im not returning 'estado' !
    

    模板:

    {% if estado %}
    {% block activos_active %}class="active"{% endblock %}
    {% endif %}
    

    模板html结果:

    class="active"
    

    :S

    2 回复  |  直到 16 年前
        1
  •  4
  •   Community Mohan Dere    9 年前

    块标记不能有条件地设置,因为它们是模板继承的一部分。我相信这是Django开发者明确的设计决定。看见 this Django ticket 以及 this other question 堆栈溢出。

        2
  •  1
  •   vikingosegundo    16 年前

    设置的一种方法 class="active" 可能就是这样

    <div{% if estado %} class="active"{% endif %}>....</div>
    
    推荐文章