我收到以下行的错误:username = login_form.cleaned_data('username'),因为在某个地方它似乎是一个字典,但我无法理解为什么。谁能告诉我,问题是什么?
views.py
def index(request):
return render(request, 'web/base.html')
def register_view(request):
register_form = UserCreationForm()
if request.method == "POST":
register_form = UserCreationForm(request.POST)
if register_form.is_valid():
register_form.save()
username = register_form.cleaned_data("username")
password = register_form.cleaned_data("password1")
user = authenticate(request, username=username, password=password)
if user:
login(request, user)
return render(request, 'web/register.html', {'register_form': register_form})
def login_view(request):
login_form = AuthenticationForm()
if request.method == 'POST':
login_form = AuthenticationForm(data=request.POST)
if login_form.is_valid():
username = login_form.cleaned_data('username')
password = login_form.cleaned_data('password')
user = authenticate(request, username=username, password=password)
if user:
login(request, user)
return render(request, 'web/login.html', {'login_form': login_form})
def logout_view(request):
logout(request)
return redirect(reverse('web:index'))
慕容森
海绵宝宝撒
森林海
相关分类