我从我的HTML表单发送用户名和密码到django后端。
<html>
<style type="text/css">
#center_align{
width: 200px;
margin: 10px auto;
}
</style>
<head>
<title>Login Form</title>
</head>
<body>
<div id = "center_align">
<h1>Login</h1>
<form method = "GET" action="http://127.0.0.1:8000/login/" >
Username :<input type ="text" name = "username"><br>
Password :<input type ="password" name = "password"><br>
<input type="submit" value="Submit">
</form>
</div>
</body>
</html>
在我的django中,我在我的观点中写了一个班级
class Login(APIView):
global User_Grps
def get(request,self):
state = ""
username = "Gauss"
password = settings.AUTH_LDAP_BIND_PASSWORD
oLdap = LDAPBackend()
try:
User = oLdap.authenticate(username=username,password=password)
print User.ldap_user.group_dns
if User is not None:
User_Grps = User.ldap_user.group_dns
else:
User_Grps = "Invalid Group"
except Exception as e:
User_Grps = "Error"
return HttpResponse(User_Grps)
如何从请求对象中检索用户名和密码?就像我需要从方法的请求参数中获取数据。