On Feb 27, 12:37 pm, andrew <always.zh...@gmail.com> wrote: > Hi, all , > > CODE: > > view.py > ----------------------------------------------------------------- > def user_login(request): > if request.method == 'POST': > form = UserLoginForm(request.POST) # get the form from POST > if form.cleaned_name(): # call the > check > method > return HttpResponseRedirect('/') > else : > return render_to_response('user/login_failed.html') > else: > form = UserLoginForm() > return > render_to_response('user/login.html',RequestContext(request, > {'form': form})) > > form.py > ------------------------------------------------------------------ > class UserLoginForm(forms.Form): > name= forms.CharField(label='Username',max_length=30) > password= forms.CharField(label='Password', widget=forms.PasswordInput > ()) > def cleaned_name(self): > username = self.cleaned_data['name'] # ERROR LINE , I tried > to get > the name value Posted by User > thePassword = self.cleaned_data['name'] > theUser = User.objects.get(name=self.cleaned_data['username']) > if theUser.password == thePassword: > return ture > else: > return false > > ERROR: > 'UserLoginForm' object has no attribute 'cleaned_data' > > Any comment or help I would be highly appreciated. > BestRegard
Why are you defining cleaned_name, and calling it from the view? That's not the way to call form validation. The form doesn't have a cleaned_data attribute until form validation is actually run, which you're not doing. Instead, call the method clean_name. Then, in the view, check form.is_valid(). This will automatically call all clean_* methods and the form-level validation. At that point, cleaned_data will exist. -- DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---