realpython / book2-exercises

Book 2 -- Exercises for the book
168 stars 203 forks source link

AttributeError at /sign_in for the mvp #2

Closed matsitka closed 10 years ago

matsitka commented 10 years ago

Hey everyone, does anyone else get an error while trying to log_in with a previous registered account?

AttributeError at /sign_in 'User' object has no attribute 'check_password'

traceback

Request Method: POST Request URL: http://127.0.0.1:8000/sign_in Django Version: 1.6.5 Exception Type: AttributeError Exception Value:
'User' object has no attribute 'check_password' Exception Location: /home/mat/Desktop/django-projects/book2-exercises/django_mvp/mvp/payments/views.py in sign_in, line 24 Python Version: 2.7.5

looks like its comming from the payments/views.py

if results[0].check_password(form.cleaned_data['password']):
def sign_in(request):
    user = None
    if request.method == 'POST':
        form = SigninForm(request.POST)
        if form.is_valid():
            results = User.objects.filter(email=form.cleaned_data['email'])
            if len(results) == 1:
                if results[0].check_password(form.cleaned_data['password']):
                    request.session['user'] = results[0].pk
                    return HttpResponseRedirect('/')
                else:
                    form.addError('Incorrect email address or password')
            else:
                form.addError('Incorrect email address or password')
    else:
        form = SigninForm()

    print form.non_field_errors()

    return render_to_response(
        'sign_in.html',
        {
            'form': form,
            'user': user
        },
        context_instance=RequestContext(request)
    )

Thanks for any headsup!

mjhea0 commented 10 years ago

This has been correct. It will be available in tomorrow's release, which will be emailed to everyone who purchased. Bed!

matsitka commented 10 years ago

Sweet! Thanks for the input :)