1. form与model的终极结合
class BookForm(forms.ModelForm): class Meta: model = models.Book fields = "__all__" labels = { "title": "书名", "price": "价格" } widgets = { "password": forms.widgets.PasswordInput(attrs={ "class": "c1" }) }
2.class Meta下常用参数
model = models.Student # 对应的Model中的类 fields = "__all__" #字段,如果是__all__, 就是表示列出所有的字段 exclude = None # 排除的字段 labels = None # 提示信息 help_texts = None # 帮助提示信息 widgets = None # 自定义插件 error_messages = None # 自定义错误信息