脆皮的助手没有生效

时间:2015-01-14 13:04:42

标签: django twitter-bootstrap-3 django-crispy-forms

似乎FormHelper根本没有任何东西。这是我的表格:

class PerguntarForm(forms.Form):
    title = forms.CharField(label='Título', max_length=200)
    categoria = forms.ModelChoiceField(queryset=Category.objects.all(), empty_label=None)
    orcamento = forms.FloatField(label='Preço máximo')

    def __init__(self, *args, **kwargs):
        super(PerguntarForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper(self)
        self.helper.layout.append(Submit('save', 'save'))
        self.helper.layout = Layout(
            PrependedText('orcamento', ',00', active=True),
        )

但是,PrependedText并未应用于“orcamento”和“orcamento”。渲染时的字段。布局附加也没有,我只是为了看看是否发生了事情。

这是输出:

<div id="div_id_title" class="form-group"><label for="id_title" class="control-label  requiredField">
                Título<span class="asteriskField">*</span></label><div class="controls "><input class="textinput textInput form-control" id="id_title" maxlength="200" name="title" type="text" /> </div></div><div id="div_id_categoria" class="form-group"><label for="id_categoria" class="control-label  requiredField">
                Categoria<span class="asteriskField">*</span></label><div class="controls "><select class="select form-control" id="id_categoria" name="categoria"><option value="4">Celular</option><option value="5">TV</option><option value="6">Computador</option></select></div></div><div id="div_id_orcamento" class="form-group"><label for="id_orcamento" class="control-label  requiredField">
                Preço máximo<span class="asteriskField">*</span></label><div class="controls "><input class="numberinput form-control" id="id_orcamento" name="orcamento" step="any" type="number" /> </div></div>

    <input type="submit" value="Enviar" />
</form>


    </div>

1 个答案:

答案 0 :(得分:1)

确保使用的是酥脆的标签,而不是松脆的过滤器。

{% load crispy_forms_tags %}
{% crispy form %}

其中form是模板中表单的名称。