Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
这个django模板if标记会发生什么?_Django_Django Templates - Fatal编程技术网

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

这个django模板if标记会发生什么?,django,django-templates,Django,Django Templates,对不起,如果我是个白痴,那么这个if标签会发生什么呢 查看返回: return render_to_response('productos/por_estado.html', {'productos':productos}, context_instance=RequestContext(request)) #Im not returning 'estado' ! 模板: {% if estado %} {% block activos_active %

对不起,如果我是个白痴,那么这个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

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

无法有条件地设置块标记,因为它们是模板继承的一部分。我相信这是Django开发者明确的设计决定。请参阅以及堆栈溢出。

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

<div{% if estado %} class="active"{% endif %}>....</div>
。。。。

设置
class=“active”
的一种方法就是这样

<div{% if estado %} class="active"{% endif %}>....</div>
。。。。

因此,我必须做一些棘手的事情,以另一种方式设置“class=”active“。谢谢你的快速回复。所以我必须做一些棘手的事情,以另一种方式设置“class=”active“。谢谢你的快速回复。