Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/21.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表单字段_Django_Twitter Bootstrap_Django Templates - Fatal编程技术网

使用其他自定义标记呈现django表单字段

使用其他自定义标记呈现django表单字段,django,twitter-bootstrap,django-templates,Django,Twitter Bootstrap,Django Templates,为了遵循Twitter引导建议的标记,我想在表单字段中添加一些额外的标记,而不仅仅是th。遵循DRY原则,我创建了一个包含以下内容的模板bootstrap\u form\u field.html: {% load widget_tweaks %} <div class="form-group{% if field.errors %} has-error{% endif %}"> <label class="col-sm-3 control-label"> {{ f

为了遵循Twitter引导建议的标记,我想在表单字段中添加一些额外的标记,而不仅仅是th
。遵循DRY原则,我创建了一个包含以下内容的模板
bootstrap\u form\u field.html

{% load widget_tweaks %}
<div class="form-group{% if field.errors %} has-error{% endif %}">
<label class="col-sm-3 control-label">
    {{ field.label }}
    {% if field.field.required %}*{% endif %}
</label>

<div class="col-sm-9">
    {% render_field field class='form-control' %}
    {% if field.errors %}
    <div class="help-block">
        <p class="text-danger">{{ field.errors.as_text }}</p>
    </div>
    {% endif %}
    <div class="help-block">
        {{ field.help_text }}
    </div>
</div>
</div>
现在,我想将帮助文本添加到我的字段中,这些字段(a)包含HTML,并且(b)通过模板语言生成。在我的一篇文章中,我问如何将这样的HTML传递给包含的模板。由于这似乎不起作用,我现在要求采用一种不同的方法来促进以下工作:

{% load widget_tweaks %}
<div class="form-group{% if field.errors %} has-error{% endif %}">
<label class="col-sm-3 control-label">
    {{ field.label }}
    {% if field.field.required %}*{% endif %}
</label>

<div class="col-sm-9">
    {% render_field field class='form-control' %}
    {% if field.errors %}
    <div class="help-block">
        <p class="text-danger">{{ field.errors.as_text }}</p>
    </div>
    {% endif %}
    <div class="help-block">
        {{ field.help_text }}
    </div>
</div>
</div>
  • 引导标记应该保留在一个位置(当前为“bootstrap\u form\u field.html”)
  • 帮助文本在模板中指定
  • 帮助文本可能包含HTML,也可能由模板语言生成