对象“用户”没有属性“创建” - Django

Oma*_*ali 2 python django synapsepay

我对遇到的错误有疑问。我有一个查询要尝试根据我的项目的 Synapse 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:\Users\OmarJandali\Desktop\opentab\opentab\tab\views.py in createUserSynapse, line 1104
Run Code Online (Sandbox Code Playgroud)

这是我当前的代码,它将创建创建新用户的请求。

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)
Run Code Online (Sandbox Code Playgroud)

现在我确实知道,使用正常的查询集,我的对象具有以下格式

User.objects.create(client, **args)
Run Code Online (Sandbox Code Playgroud)

但是当我这样做时,我收到一条错误消息

正在传递两个参数,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:\Users\OmarJandali\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\manager.py in manager_method, line 127
Run Code Online (Sandbox Code Playgroud)

更新

客户端需要传入 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)
Run Code Online (Sandbox Code Playgroud)

此外,这里还有一个指向 api 开发人员创建的 api 示例的 github 链接。

https://github.com/synapsepay/SynapsePayRest-Python

客户端必须通过 api 调用传递

nev*_*ner 6

Create 方法只有关键字参数。将您的代码重写为:

User.objects.create(client=client, **args)
Run Code Online (Sandbox Code Playgroud)

更新

我刚刚发现您正在使用第三方软件包。因此,您需要像这样导入 User 类from synapse_pay_rest import User as SynapseUser并在代码中使用 SynapseUser:SynapseUser.create(clients, **argss)