Django crispy-forms显示InlineRadios上方的错误,但低于其他错误

时间:2015-08-20 09:36:19

标签: css django django-forms django-crispy-forms

在模型中

class TourLead(models.Model):
    GENDER_CHOICES = (
        ('M', 'Male'),
        ('F', 'Female'),
    )

    name = models.CharField(max_length=256)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)

表格

gender = forms.ChoiceField(widget=forms.RadioSelect(), choices=TourLead.GENDER_CHOICES)

这是布局:

Layout(
        Field('name', placeholder='John Doe'),
        InlineRadios('gender'),
        # ...
    )

enter image description here

我的问题是如何在输入

之后将错误置于其后?

我尝试了一些css:

[id^="error"] {
    position: absolute;
    top: 100%;
    width: 100%;
}

但无法弄清楚如何在...之后显示某种间隔(边距...)。

enter image description here

1 个答案:

答案 0 :(得分:0)

我已经解决了这个指定的自定义模板

InlineRadios('gender', template='radioselect_inline.html'),

只需将radioselect.htmlsite-packages/...复制到您的静态文件夹,然后将'radioselect_inline.html'中的最后一个包含更改为

{% include 'radioselect.html' %}

并在radioselect.html移动{% include 'bootstrap3/layout/field_errors_block.html' %}到最后,如下所示

    #...
    {% endfor %}

    {% include 'bootstrap3/layout/field_errors_block.html' %}
    {% include 'bootstrap3/layout/help_text.html' %}
</div>

此时此刻您还会遇到错误https://github.com/maraujop/django-crispy-forms/issues/361,因此只需将其降级为django-crispy-forms==1.4.0即可使用!