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更改包含在.html表单模板中的标签-例如“from”;加上「;至;“保存”;_Django - Fatal编程技术网

django更改包含在.html表单模板中的标签-例如“from”;加上「;至;“保存”;

django更改包含在.html表单模板中的标签-例如“from”;加上「;至;“保存”;,django,Django,我已经编写了一个表单模板,可以在包含标签的不同模板中使用 {% include "crm/contact_form.html" %} 此表单包含一个提交按钮。现在我想根据表单使用的情况更改按钮的标签 例如,如果表单包含在添加模板中,则标签应为“添加”,而在详细信息模板中,标签应为“保存” 如何实现这一点?您需要将标签放入上下文变量中,以便contact_form.html模板可以使用它,或者从{%include%}切换到允许您传递如下参数的: {% load contact_form %}

我已经编写了一个表单模板,可以在包含标签的不同模板中使用

 {% include "crm/contact_form.html" %}
此表单包含一个提交按钮。现在我想根据表单使用的情况更改按钮的标签

例如,如果表单包含在添加模板中,则标签应为“添加”,而在详细信息模板中,标签应为“保存”


如何实现这一点?

您需要将标签放入上下文变量中,以便
contact_form.html
模板可以使用它,或者从
{%include%}
切换到允许您传递如下参数的:

{% load contact_form %}
...
{% contact_form mylabel %}

您需要将标签放入一个上下文变量中,
contact_form.html
模板可以使用它,或者从
{%include%}
切换到允许您传递如下参数的:

{% load contact_form %}
...
{% contact_form mylabel %}

作为Van方法的替代方法,您可以通过
with
在封闭模板中设置变量:

{% with "Add" as mylabel %}
  {% include "crm/contact_form.html" %}
{% endwith %}

作为Van方法的替代方法,您可以通过
with
在封闭模板中设置变量:

{% with "Add" as mylabel %}
  {% include "crm/contact_form.html" %}
{% endwith %}
因为,您可以将include和with标记组合在一起

{% include "form_snippet.html" with form=comment_form %}
因为,您可以将include和with标记组合在一起

{% include "form_snippet.html" with form=comment_form %}

谢谢你,真管用!我已经选择了包含标签,它在这个用例中工作得很好。谢谢你的工作!我选择了inclusion标签,它在这个用例中工作得很好。