Django – Hide field from a form

The Django’s form.as_table in a template would automatically create fields listed in the form. If a specific field has to be hidden from a form, it can be done like below:

class KiteworksEvalForm(forms.Form):
    '''
    create online order for acct
    '''
    ...
    msp_host = forms.BooleanField(required=False, label="MSP Host", help_text="Enable if server need to have Multi-Tenant feature enabled. Only valid for VM environments.")
    ...

    def __init__(self, *args, **kwargs):
        super(KiteworksEvalForm, self).__init__(*args, **kwargs)
        self.fields['msp_host'].widget = HiddenInput()

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s