form應用上bootstrop樣式,form能夠直接繼承這個類python
# BootstropForm class BSForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # 自定義操做 for field in self.fields.values(): if not isinstance(field, forms.BooleanField): # field.widget.attrs['class'] = 'form-control' field.widget.attrs.update({'class': 'form-control'})