我尝试在Django中测试我的视图,当我运行这个时,我得到了错误
第一个
我不确定应该传递什么作为路径名。
def login_request(request):
if request.method == "POST":
form = AuthenticationForm(request, data=request.POST)
if form.is_valid():
username = form.cleaned_data.get('username')
password = form.cleaned_data.get('password')
user = authenticate(username=username, password=password)
if user is not None:
login(request, user)
messages.info(request, f"You are now logged in as {username}.")
return redirect("main:homepage")
else:
messages.error(request,"Invalid username or password.")
else:
messages.error(request,"Invalid username or password.")
form = AuthenticationForm()
return render(request=request, template_name="login.html", context={"login_form":form})
1条答案
按热度按时间8yparm6h1#
您需要示例化
Client
类,您当前只是直接引用该类。