Pav*_*T S 5 python django django-forms django-crispy-forms
我有一个模型表单,我想在其中将 required 属性设置为 True 以进行电子邮件验证
场地:-email
class RegisterMyBuisinessForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.form_method = 'post'
self.helper.form_action = '/registermybuisness/'
Field('email', type='email')
self.helper.add_input(Submit('submit', 'Submit',css_class="btn c-theme-btn c-btn-square c-btn-bold c-btn-uppercase"))
super(RegisterMyBuisinessForm, self).__init__(*args, **kwargs)
class Meta:
model = RegistermyBusiness
fields = ['name','email', 'org_name', 'contact','business_description','store_address','message','store_landmark','business_type','city']
Run Code Online (Sandbox Code Playgroud)
我试过
self.fields['email'].required=True
Run Code Online (Sandbox Code Playgroud)
这导致类 RegisterMyBuisinessForm 没有字段错误
您可以self.fields['email']在__init__方法中进行更改。你需要先打电话super()。
class RegisterMyBuisinessForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
...
super(RegisterMyBuisinessForm, self).__init__(*args, **kwargs)
self.fields['email'].required = True
...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2197 次 |
| 最近记录: |