On Fri, Mar 6, 2015 at 10:37 AM, younger.shen <younger.x.s...@gmail.com> wrote: > Hello everyone: > > i use django since last year, and now i can not stand the django form any > more, hard to use , especially custom error message , i use laravel for php > development , and validator of laravel is very easy to use and very clean > code , so i hack a small plugin . > > https://github.com/youngershen/django-laravel-validator > > i want your opinion my friends. talk to me please , what is your opinion > about django form.
I prefer django forms to that style. Each time the form is generated it must determine what the options are for a field by parsing strings, which is ugly. If you don't invest time in to learning how django's forms work, you will always prefer a form system you already understand. As an example, this is your RegistValidator as a django form: class RegistValidator(forms.Form): email = forms.EmailField() password = forms.PasswordField(min_length=8) password_confirm = forms.PasswordField(min_length=8) captcha_0 = forms.CharField() captcha_1 = forms.CharField() def clean(self): data = super(RegistValidator, self).clean() if data['password'] != data['password_confirm']: self.add_error('password', u'密码不匹配') try: CaptchaStore.objects.get( response=data['captcha_1'], hashkey=data['captcha_0'], expiration__gt=get_safe_now()).delete() except CaptchaStore.DoesNotExist: self.add_error('captcha_0', u'验证码错误') self.add_error('captcha_1', u'验证码错误') def clean_email(self): if User.objects.filter(email=self.cleaned_data['email']).exists(): raise forms.ValidationError(u'该用户已存在') Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at http://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAFHbX1Li4%3Dujpbsn8EJ-kKF_x%2BjkB4_LvzqTbw1Lkp%3D4r7A8wA%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.