开发者

django cleaned_data [help]

开发者 https://www.devze.com 2023-01-10 16:27 出处:网络
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

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 = for开发者_运维技巧m.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.

0

精彩评论

暂无评论...
验证码 换一张
取 消