Python 为什么Django Django.contrib.auth.authenticate需要就地参数?
为什么Django 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'] ) 可以有许多不同
user=authenticate(
username=request.POST['username'],
password=request.POST['password']
)
而不是与
user=authenticate(
request.POST['username'],
request.POST['password']
)
可以有许多不同的身份验证后端,它们可能使用不同于用户名和密码的身份验证方式,即某种令牌。要使
authenticate()
方法保持通用性,必须以这种方式实现它。表示“默认情况下,它将凭据作为关键字参数、用户名和密码。”关键部分是:默认情况下。
唯一可以作为位置参数给出的参数是可选的
request
参数。,因为它不了解django需要与哪个字段进行比较,因为身份验证可以由自定义身份验证后端修改,您可以使用电子邮件代替用户名,因此需要传递列名