Django的forms表单组件批量设置字段样式

时间:2023-03-08 17:46:11
from django import forms
from . import models
class UserInfoModelForms(forms.ModelForm):
class Meta:
model = models.UserInfo
fields = "__all__" def __init__(self,*args,**kwargs):
super(UserInfoModelForms, self).__init__(*args,**kwargs)
for name,field in self.fields.items():
field.widget.attrs['class'] = 'form-control'