django get()调用中缺少“path”参数

wd2eg0qa  于 2022-12-01  发布在  Go
关注(0)|答案(1)|浏览(106)

我尝试在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})
8yparm6h

8yparm6h1#

您需要示例化Client类,您当前只是直接引用该类。

client = Client()

相关问题