Django表单字段不是酥脆的形式帮助器没有出现

时间:2014-04-15 04:22:05

标签: django django-crispy-forms

我有这种形式的信用卡网关:

class CreditCardForm(forms.Form):
    SessionId = forms.CharField(widget=forms.HiddenInput())
    CardHolderName = forms.CharField(label=ugettext('Cardholder Name'), max_length=64, required=True)
    CardNumber = forms.CharField(label=ugettext("Card Number"), min_length=12, max_length=20, required=True)
    ExpiryMonth = forms.CharField(label="", min_length=2, max_length=2, required=True)
    ExpiryYear = forms.CharField(label="", min_length=2, max_length=2, required=True)
    Cvc2 = forms.CharField(label=ugettext("CVC"), min_length=3, max_length=4, required=True)
    UserTxnData1 = forms.CharField(label=ugettext("Card Alias"), max_length=64, required=False)
    helper = Helper()

我想为不同的信用卡网关重用这个助手:

class Helper(FormHelper):
    layout = Layout(Fieldset('Card Details',
          RowFluid(Column(Field('CardHolderName',css_class="large-8 small-12")),
          RowFluid(Column(Field('CardNumber',css_class="large-8 small-12")),
          RowFluid(Column(Field('ExpiryMonth',css_class="large-8 small-12")),
          RowFluid(Column(Field('ExpiryYear',css_class="large-8 small-12")),
          RowFluid(Column(Field('Cvc2',css_class="large-8 small-12")),
          RowFluid(Column(Field('UserTxnData1',css_class="large-8 small-12")),
     ))

问题是,SessionId特定于此网关表单,并且未在帮助程序中定义,并且它未以呈现的形式显示。

1 个答案:

答案 0 :(得分:0)

我认为crispy表单只显示你在布局助手中定义的内容(如果你使用的话)。要隐藏该字段,请尝试将其添加为字段,并将以下内容添加到表单中:

class Meta:
    model = YourModel
    fields = (
        'session_id',
        ..., # all the fields you want to include
    )
    widgets = {
        'session_id': forms.HiddenInput(),
    }