python - 'input' 是 print() 的无效关键字参数

标签 python django graphene-python

我正在使用 graphene-django 作为 api。我正在尝试创建一个突变来创建一个具有公司外键的品牌。当我改变时,我收到以下错误“'input' 是 print() 的无效关键字参数”。我不明白为什么会抛出这个错误。

这是我的突变

class BrandInput(graphene.InputObjectType):

    company = graphene.List(CompanyInput)
    name = graphene.String()
    website = graphene.String()
    description = graphene.String()
    country = graphene.String()
    city = graphene.String()
    address = graphene.String()


    class CreateBrand(graphene.Mutation):

        class Arguments:

            input = BrandInput(description="These fields are required", required=True)


        class Meta:

            description = "Create Brand Mutation"

        errors = graphene.String()
        brand = graphene.Field(BrandNode)

        @staticmethod
        def mutate(root, info, **args):
            print('args', args, **args)
            if not info.context.user.is_authenticated:
                return CreateBrand(errors=json.dumps('Please Login to list your brand'))
            try:
                company = models.Company.objects.get(slug=args.get('input')['company'])
                if company:
                    brand = models.Brand.objects.create(
                        company=company,
                        name=args.get('input')['name'],
                        slug = args.get('input')['slug'],
                        website = args.get('input')['website'],
                        description = args.get('input')['description'],
                        country = args.get('input')['country'],
                        city = args.get('input')['city'],
                        address = args.get('input')['address'],
                    )
                    return CreateBrand(brand=brand, errors=null)
            except models.Company.DoesNotExist:
                return CreateBrand(errors=json.dumps('Company should be required'))

我对 company = graphene.List(CompanyInput) 感到怀疑,所以我将其更改为 company = graphene.String() 并提供了公司的名称,所以我可以在改变品牌时找到公司实例。但是我得到了同样的错误。

突变查询是

mutation {
  createBrand(input: {company: "wafty-company", name: "Wafty Brand", website: "www.wafty.com", description: "Wafty brand description", country: "Nepal", city: "Kathmandu", address: "Baneshwor", pinCode: "44600", operationDate: "2018-10-02 15:32:37", franchisingDate: "2018-10-02 15:32:37", numberOfFranchises: "0-10", numberOfOutlets: "0-10"}) {
    errors
    brand {
      name
      slug
      website
    }
  }
}

最佳答案

当您尝试将像这样的参数 **args 传递给 print() 时,此参数将被解压缩为关键字参数,这将引发错误,因为 print() 不期望像 mutate() 方法那样的参数。所以你需要删除**args:

print('args', args)

关于python - 'input' 是 print() 的无效关键字参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52612286/

相关文章:

python - 谷歌 JAX 一维卷积神经网络

python - Tensorflow 2 字符串标签到 one_hot

django - 如何重命名在 Django 模型中上传的图像

python - Graphql Django 获取嵌套对象属性的最佳方法

python - Graphite 烯 Django 返回空值

Python 脚本通过双击和 IDLE 运行,但不通过 Windows CMD shell 运行

python - 在 Jupyter 笔记本中显示 Flask 应用程序输出

django - graphql-django 使用可选字段成语更新突变?

python - django 1.6.5 密码重置电子邮件检查有效链接

python - 有序对象集的 Django 输出索引