Django crispy-forms 显示错误高于 InlineRadios 但低于其他错误
Django crispy-forms shows errors above InlineRadios but below others
模型中
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'),
# ...
)
我的问题是如何将错误 [=32=] 始终放在 输入之后?
我试过一些 css:
[id^="error"] {
position: absolute;
top: 100%;
width: 100%;
}
但无法弄清楚如何在...之后显示某种间隔符(边距...)
我已经解决了这个指定的自定义模板
InlineRadios('gender', template='radioselect_inline.html'),
只需将它和 radioselect.html
从 site-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
就可以了!
模型中
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'),
# ...
)
我的问题是如何将错误 [=32=] 始终放在 输入之后?
我试过一些 css:
[id^="error"] {
position: absolute;
top: 100%;
width: 100%;
}
但无法弄清楚如何在...之后显示某种间隔符(边距...)
我已经解决了这个指定的自定义模板
InlineRadios('gender', template='radioselect_inline.html'),
只需将它和 radioselect.html
从 site-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
就可以了!