form與model的終極結合。django
from django import forms
class BookForm(forms.ModelForm): class Meta: model = models.Book fields = "__all__" labels = { "title": "書名", "price": "價格" } widgets = { "password": forms.widgets.PasswordInput(attrs={"class": "c1"}), }
class Meta:下經常使用參數:插件
model = models.Student # 對應的Model中的類 fields = "__all__" # 字段,若是是__all__,就是表示列出全部的字段 exclude = None # 排除的字段 labels = None # 提示信息 help_texts = None # 幫助提示信息 widgets = None # 自定義插件 error_messages = None # 自定義錯誤信息