如何在crispy-formDjango的InlineCheckboxes中的同一列中的行之间添加空格并使元素对齐?

问题描述

我有一个CheckBoxSelectMultiple表单字段,我使用InlineCheckBoxes中的crispy-forms使所有这些复选框都内联。由于我没有图像,因此我将使用代码片段作为示例。

这就是我想要的表单在html中的样子,我将使用stars而不是框

     *name1    *name2    *name3    *name4
     *name5    *name6    *name7    *name8
     *name9    *name10   *name11   *name13

我该怎么做才能在每行之间添加更多空间并使其垂直对齐(如上图所示)?

这是我的表格。py

class AttendanceForm(forms.ModelForm):
    class Meta:
        model = Attendance
        fields = ['student',]
        widgets = {'student': forms.CheckBoxSelectMultiple()}

    def __init__(self,class_pk,current_user,*args,**kwargs):
        super(AttendanceForm,self).__init__(*args,**kwargs)
        current_student = Class.objects.get(id=class_pk)
        self.helper = FormHelper(self)
        self.fields['student'].queryset = current_student.student.order_by('first_name')
        self.helper.layout = Layout(
            InlineCheckBoxes('student')
        )

我当前的html。 (它未如上图所示完全对齐!)

<form method="POST" class="ml-auto mr-auto">
  {% csrf_token %} 
  <div style="text-align: justify;">{% crispy form form.helper %}</div>
  <button
    type="submit"
    class="btn btn-success btn-sm"
    style="font-size: 15px"
  >
    Check
  </button>
</form>

先谢谢!

解决方法

现在,我要做的就是使所有元素内联显示,并在每行多于一行的位置添加空格。因此,我不需要为此使用酥脆的形式。我从模板和表单类中删除了所有香脆的表单标签,然后在模板中我要做的就是:

imshow('predictions.jpg')

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...