[英]TypeError: __init__() got multiple values for keyword argument 'customer'
customer = CustomerProfile.objects.get(pk=4)
ipdb> SimilarCustomerFinder(self, customer=customer, fields=self.fields)
*** TypeError: __init__() got multiple values for keyword argument 'customer'
In SimilarCustomerFinder
class, I have 在
SimilarCustomerFinder
类中,我有
def __init__(self, customer, fields):
self._matches = {}
props = self.__class__.__dict__.keys()
self.customer = customer
self.fields = fields
self.checks = [k for k in props if k.startswith('check_')]
if customer:
self.user_id = customer.user.pk
else:
self.user_id = -1
for check in self.checks:
c = check.replace('+', '_')
getattr(self, c)()
I am struggling with this error. 我正在努力解决这个错误。 How could I fix it?
我该怎么办呢? If I remove
customer=customer
, I got *** AttributeError: 'CustomerUpdateForm' object has no attribute 'user'
, why? 如果我删除
customer=customer
,我得到*** AttributeError: 'CustomerUpdateForm' object has no attribute 'user'
,为什么?
Given the ipdb
output it seems like you're trying to create an instance using this command: 鉴于
ipdb
输出,您似乎正在尝试使用此命令创建实例:
SimilarCustomerFinder(self, customer=customer, fields=self.fields)
However self
is an implicitly passed argument so you shouldn't pass it in explicitly. 但是
self
是一个隐式传递的参数,所以你不应该明确地传递它。 Like this: 像这样:
SimilarCustomerFinder(customer=customer, fields=self.fields)
Or if you really intended to pass it in explicitly (which would be really weird and probably doesn't do what you intend - but who knows ...) you have to call the method explicitly on the class: 或者,如果你真的打算明确地传递它(这可能非常奇怪,可能不会按照你的意图 - 但谁知道......)你必须在类上显式调用该方法:
SimilarCustomerFinder.__init__(self, customer=customer, fields=self.fields)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.