如何在 Django 中洗掉此驗證? 
Django 中的代碼是這樣的:
image = models.ImageField(upload_to="data", null=True, blank=True)
uj5u.com熱心網友回復:
如果在 a 中設定欄位ModelForm,它將不再由相應的模型欄位構建,因此不會blank=True考慮。
您可以做的只是覆寫小部件,因此請使用:
class SomeModelForm(forms.ModelForm):
# no image = …
class Meta:
model = SomeModel
fields = ['image', 'and', 'other', 'fields']
widgets = {
'image': forms.FileInput(attrs={'class': 'file-upload-input', 'id': 'file-selector'})
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/370652.html
