简体   繁体   中英

django cleaned_data [help]

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'

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM