我有一个关于我遇到的错误的问题。我有一个根据我的项目的突触API发送的查询。我目前正在尝试使用API创建新用户。每次我尝试发送请求时,我都会收到一条消息,即用户对象没有创建。这是错误。
AttributeError at /setup_profile/
type object 'User' has no attribute 'create'
Request Method: POST
Request URL: http://127.0.0.1:8000/setup_profile/
Django Version: 1.8.6
Exception Type: AttributeError
Exception Value:
type object 'User' has no attribute 'create'
Exception Location: C:UsersOmarJandaliDesktopopentabopentabtabviews.py in createUserSynapse, line 1104
这是我拥有的当前代码,它将创建创建新用户的请求。
def createUserSynapse(request):
args = {
'email': 'hello@synapsepay.com',
'phone_number': '555-555-5555',
'legal_name': 'Hello McHello',
'note': ':)', # optional
'supp_id': '123abc', # optional
'is_business': True,
'cip_tag': 1
}
user = User.create(client, **args)
print(user)
现在,我确实知道,使用普通查询集,我的对象以以下格式
User.objects.create(client, **args)
但是当我这样做时,我会遇到一个错误的错误
正在传递两个参数,需要1个参数,所以我认为许多变量正在传递...我不确定错误来自...
这是我使用user.objects.create(client,** args)
时遇到的错误TypeError at /setup_profile/
create() takes 1 positional argument but 2 were given
Request Method: POST
Request URL: http://127.0.0.1:8000/setup_profile/
Django Version: 1.8.6
Exception Type: TypeError
Exception Value:
create() takes 1 positional argument but 2 were given
Exception Location: C:UsersOmarJandaliAppDataLocalProgramsPythonPython36libsite-packagesdjangodbmodelsmanager.py in manager_method, line 127
更新
客户需要传递到API调用中,其中包含以下内容:
import os
from synapse_pay_rest import Client
args = {
'client_id': 'client_id_...6YiBl',
'client_secret': 'client_secret_...kC3IF',
'fingerprint': '...dd48b',
'ip_address': '127.0.0.1',
'development_mode':True,
'logging':False
}
client = Client(**args)
另外,这是API开发人员创建的API样品的GitHub链接。
https://github.com/synapsepay/synapsepayrest-python
必须使用API调用
创建方法只有关键词参数。重写您的代码:
User.objects.create(client=client, **args)
update
我刚刚发现您正在使用第三方软件包。因此,您需要像以下from synapse_pay_rest import User as SynapseUser
一样导入用户类,并在代码中使用Synapseuser:SynapseUser.create(clients, **argss)