带有和不带有连字符(from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
class SignUpForm(forms.Form):
Username=forms.CharField(required=True)
Password=forms.CharField(widget=forms.PasswordInput,required=True)
Confirm_Password=forms.CharField(widget=forms.PasswordInput,required=True)
def __init__(self,*args,**kwargs):
super(SignUpForm,self).__init__(*args)
self.helper=FormHelper()
self.helper.method='POST'
self.helper.add_input(Submit('gobtn','Login',css_class='btn-success'))
def clean(self):
cleaned_data = super(SignUpForm, self).clean()
password = cleaned_data.get('Password')
password_confirm = cleaned_data.get('Confirm_password')
if password != password_confirm:
raise forms.ValidationError("The two password fields must match.")
return cleaned_data
)的javascript日期看起来都不同。
def myview(request):
#your logic here
context={}
if request.method == "GET":
context['form']= SignUpForm()
else:
#POST request block
if SignUpForm(request.POST).is_valid():
#do what you like here
else:
#if form is invalid
context['form']= SignUpForm(request.POST) # this will render if validation errors so you can remove your if errors block in html
render(request,'template_name.html',context)
您能解释一下这种行为吗?