Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么Django Django.contrib.auth.authenticate需要就地参数?_Python_Django_Authentication - Fatal编程技术网

Python 为什么Django Django.contrib.auth.authenticate需要就地参数?

Python 为什么Django Django.contrib.auth.authenticate需要就地参数?,python,django,authentication,Python,Django,Authentication,为什么Django authenticate函数只与此函数一起工作 user=authenticate( username=request.POST['username'], password=request.POST['password'] ) 而不是与 user=authenticate( request.POST['username'], request.POST['password'] ) 可以有许多不同

为什么Django authenticate函数只与此函数一起工作

user=authenticate(
        username=request.POST['username'],
        password=request.POST['password']
    )
而不是与

user=authenticate(
        request.POST['username'],
        request.POST['password']
    )

可以有许多不同的身份验证后端,它们可能使用不同于用户名和密码的身份验证方式,即某种令牌。要使
authenticate()
方法保持通用性,必须以这种方式实现它。
表示“默认情况下,它将凭据作为关键字参数、用户名和密码。”关键部分是:默认情况下。

唯一可以作为位置参数给出的参数是可选的
request
参数。

,因为它不了解django需要与哪个字段进行比较,因为身份验证可以由自定义身份验证后端修改,您可以使用电子邮件代替用户名,因此需要传递列名