我使用crispy来呈现我的表单,但是在不影响其他字段的情况下呈现一个内联字段时遇到了问题。
本表格:
class SettingsUpdateForm(forms.ModelForm):
class Meta:
model = User
fields = ('about_text', 'github_name')
labels = {
'about_text': '',
'github_name': 'github.com/' # TODO make inline with field
}
widgets = {
'about_text': forms.Textarea(attrs={'placeholder': 'Describe yourself!💯'}),
'github_name': forms.TextInput(attrs={'placeholder': 'your_github_name'})
}
help_texts = {
'github_name': 'Showcase a project instead: <em>/username/fav_project</em>',
}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.helper = FormHelper(self) # this is required to display the help_texts
呈现如下:
我希望github/
标签与输入字段在同一行。我该怎么做呢?
水平形式将使所有标签的一部分,引导网格模型-我不希望。
我也试过使用内联表单,但也不起作用。
3条答案
按热度按时间x4shl7ld1#
我自己破解的。这是我提出的解决方案:
我不得不删除
github_name
的标签。但现在看起来不错:inn6fuwd2#
我找到了另一个解决办法。这并不是作者想要实现的,但在许多情况下可能是有用的。我对输入字段使用了PrependText属性。
表单看起来像这样:
这适用于crispy-bootstrap 5
avwztpqn3#
在你的小部件中,你需要包含一个属性,让crispyforms知道如何呈现它。试试这个:
如果成功了就告诉我