Django crispy表单:在复选框旁边添加文字?

时间:2015-06-30 10:11:43

标签: python django checkbox django-crispy-forms

这似乎很简单,但我无法弄清楚如何在我的复选框旁边添加一些文字。我不想覆盖模板(我想我不需要)。 现在,我有一个可以使用的复选框,但如何在复选框的右侧放置一些像“我同意TOS”的文字?

以下是我所拥有的: https://www.dropbox.com/s/i3n5rivhzfvo2ms/Screenshot%202015-06-30%2012.10.46.png?dl=0

class TenantSignupForm(forms.Form):
    email = forms.EmailField()
    password = forms.CharField(
        widget=forms.PasswordInput(),
        validators=[RegexValidator(regex=r'[A-Za-z0-9@#$%^&+=]{8,}', code=None),
                    MaxLengthValidator(32)])
    password_confirmation = forms.CharField(
        widget=forms.PasswordInput())
    agree_tos = forms.BooleanField()

    def __init__(self, *args, **kwargs):
        super(TenantSignupForm, self).__init__(*args, **kwargs)
        self.helper = unvariable_helper(self)
        self.helper.form_class = 'm-t'
        self.helper.form_action = 'signup'
        self.helper.layout = Layout(
            Field('email', placeholder="Email"),
            Field('password', placeholder="Password"),
            Field('password_confirmation', placeholder="Confirm your password"),
            Field('agree_tos', wrapper_class='i-checks'),
            FormActions(
                Submit('signup',
                       'Register',
                       css_class='btn btn-primary block full-width m-b'
                      )
                )
        )

3 个答案:

答案 0 :(得分:1)

我不熟悉public class SlidingPanel extends LinearLayout { private Paint innerPaint, borderPaint ; public SlidingPanel(Context context, AttributeSet attrs) { super(context, attrs); init(); } public SlidingPanel(Context context) { super(context); init(); } private void init() { innerPaint = new Paint(); innerPaint.setARGB(100, 25, 25, 75); //gray innerPaint.setAntiAlias(true); borderPaint = new Paint(); borderPaint.setARGB(255, 255, 255, 255); borderPaint.setAntiAlias(true); borderPaint.setStyle(Style.STROKE); borderPaint.setStrokeWidth(5); } public void setInnerPaint(Paint innerPaint) { this.innerPaint = innerPaint; } public void setBorderPaint(Paint borderPaint) { this.borderPaint = borderPaint; } @Override protected void dispatchDraw(Canvas canvas) { RectF drawRect = new RectF(); drawRect.set(0,0, getMeasuredWidth(), getMeasuredHeight()); canvas.drawRoundRect(drawRect, 5, 5, innerPaint); canvas.drawRoundRect(drawRect, 5, 5, borderPaint); super.dispatchDraw(canvas); } } ,但可能会添加crispy-forms帮助

help_text

更新:另一个猜测

agree_tos = forms.BooleanField(help_text="I Agree TOS")

答案 1 :(得分:0)

如果您在模板中单独显示每个表单窗口小部件,则可以在以下窗口小部件旁边添加所需的文本。

{{ form.agree_tos }} 

答案 2 :(得分:0)

至于我,最好的方法是在此字段中使用特定模板:

Field('agree_tos', template="{0}/tos.html".format(TEMPLATE_PACK))

根据所使用的Template_pack,您必须查看相应目录中的默认模板(field.html)(例如,uni_form或bootstrap),并快速轻松地制作自己的模板。

相关问题