views:

48

answers:

1

ok so I have the following problem i`ve looked around but I cant find a solution ...

lets say I have the following forms.py

from django import forms

class LoginForm(forms.Form):
    _username = forms.CharField()
    _password = forms.CharField()

and in views.py I have

def index(request):
    if request.method == 'POST':
        form = LoginForm(request.POST)
    else:
        form = LoginForm()

    if form.is_valid:
        username = form.cleaned_data['_username']
        password = form.cleaned_data['_password']
        if check_credential(username, password):
            request.session['_username'] = username
            request.session['_password'] = password

I`m using void@void:~$ django-admin --version 1.1.1

I`m using djangobook to learn django they used an old ver of django that had clean_data ...ive tryed using

from django import newforms as forms 

but the result was the same ...

'LoginForm' object has no attribute 'cleaned_data'
+7  A: 

form.is_valid is a function. Use it as

if form.is_valid():
    # actions

Only after is_valid() internally had called each field's own clean method, the form has dict named cleaned_data.

simplyharsh
ahhh damn it so this was the problem ... I should`ve read the code more closely ... thx anyway :)
void
@void: It is considered good form to accept the answer if the solution worked for you :)
Manoj Govindan