我想在应用程序中添加身份验证功能。我有以下代码段:
user = User.objects.create_user('jkd')
user.set_password('space')
user.save
user = authenticate(username='jkd', password='space')
print "User:",user
它总是打印"用户:无"。我还在我的设置中添加了下面的文件:
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend', # default
# any other authentication backends
)
我在不同线程中经历了同一问题的答案,但对我没有帮助。
您的代码中有错字,因此记录尚未保存
从
更改user.save
to
user.save()