无法覆盖AuthenticationForm

时间:2018-06-06 10:29:25

标签: django django-forms django-authentication

我尝试添加一个额外的检查,表明用户在该字段中有某些文本,但我无法重新定义AuthenticationForm。 Forms.py:

from django.contrib.auth.forms import AuthenticationForm as BaseAuthenticationForm 
from django.contrib.auth.models import User

class AuthenticationForm(BaseAuthenticationForm):
        print('here')

class AuthenticationForm(BaseAuthenticationForm):
    def clean(self):
        print('hi')
        return self.cleaned_data

    class Meta:
        model = User

不起作用。感觉是我没有进入它们,因为该行的输出是第一个命令。 Views.py:

from .forms import AuthenticationForm

def LogIn(request):
if request.method == 'POST':
    form = AuthenticationForm(request.POST)
    if form.is_valid():
        print('hi there')
        username = form.cleaned_data.get('username')
        password = form.cleaned_data.get('password')
        user = authenticate(username=username, password=password)
        login(request, user)
        return redirect('/')
    else:
        print(form.errors)
else:
    form = AuthenticationForm()
return render(request, 'userprocessing/login.html', {'form': form})

所有print我只用来检查哪些有用。我究竟做错了什么?登记表已经重新定义并且已经过问题的授权。

0 个答案:

没有答案