我正在尝试使用Login方法登录从外部API验证的用户。
def whmcs_login(request):
if request.method == 'POST':
username1 = request.POST['username'];
password1 = request.POST['password'];
whmcs1 = whmcs()
login = whmcs1.login(username1=username1,password1=password1)
if login['result'] == 'success':
userid = login['userid']
try:
whmcs_i = Profile.objects.get(whmcsid=userid)
user = User.objects.get(id=whmcs_i.user_id)
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
except Profile.DoesNotExist:
whmcs_data = whmcs1.getuser(userid=userid)
user = User.objects.create(username='random',
password='33e32121',
first_name=whmcs_data['firstname'],
last_name=whmcs_data['lastname'])
user.profile.whmcsid = userid
user.save()
user.backend = 'django.contrib.auth.backends.ModelBackend'
login(request, user)
当我使用登录方法时,我一直收到以下错误 “'dict'对象不可调用”
回溯
文件“/Volumes/Development/ssb-panel/ssbenv/lib/python3.6/site-packages/django/core/handlers/exception.py”,第41行,内在 response = get_response(request)
文件“/Volumes/Development/ssb-panel/ssbenv/lib/python3.6/site-packages/django/core/handlers/base.py”,第249行,在_legacy_get_response中 response = self._get_response(request)
文件“/Volumes/Development/ssb-panel/ssbenv/lib/python3.6/site-packages/django/core/handlers/base.py”,第187行,在_get_response中 response = self.process_exception_by_middleware(e,request)
文件“/Volumes/Development/ssb-panel/ssbenv/lib/python3.6/site-packages/django/core/handlers/base.py”,第185行,在_get_response中 response = wrapped_callback(request,* callback_args,** callback_kwargs)
文件“/Volumes/Development/ssb-panel/SSBpanel/main/views.py”,第55行,在whmcs_login中 登录(请求,用户) TypeError:'dict'对象不可调用
固定。变量名称不匹配。我做了一个名为login的dict,因为我无法使用Django的登录方法。