ฉันพยายามจัดเก็บ ID ของผู้ใช้ในเซสชันโดยใช้ django.contrib.auth.login แต่มันไม่ทำงานไม่เป็นไปตามที่คาดไว้
ฉันได้รับข้อผิดพลาด เข้าสู่ระบบ () รับ 1 อาร์กิวเมนต์ (ให้ 2)
ด้วยการเข้าสู่ระบบ (ผู้ใช้) ฉันได้รับ AttributeError ที่ / login / User 'object ไม่มีแอตทริบิวต์' method '
ฉันใช้แบบฟอร์มตัวอย่างที่แก้ไขเล็กน้อยhttp://docs.djangoproject.com/en/dev/topics/auth/ :
from django.shortcuts import render_to_response
from django.contrib.auth import authenticate, login
def login(request):
msg = []
if request.method == 'POST':
username = request.POST['u']
password = request.POST['p']
user = authenticate(username=username, password=password)
if user is not None:
if user.is_active:
login(request, user)
msg.append("login successful")
else:
msg.append("disabled account")
else:
msg.append("invalid login")
return render_to_response('login.html', {'errors': msg})
ไม่มีอะไรพิเศษเกี่ยวกับ login.html:
<html>
<head>
<title></title>
</head>
<body>
<form action="/login/" method="post">
Login: <input type="text" name="u">
<br/>
Password: <input type="password" name="p">
<input type="submit" value="Login">
</form>
{% if errors %}
<ul>
{% for error in errors %}
<li>{{ error }}</li>
{% endfor %}
</ul>
{% endif %}
</body>
</html>
ใครมีความคิดที่จะทำให้การเข้าสู่ระบบ () ทำงาน