[英]Overriden @classmethod, type exception
我試圖用我自己的'snAccount'類擴展名稱為'Account'的類(來自django-user-accounts應用程序),因為我需要為每個用戶帳戶添加一些額外的字段。 當我嘗試用我的父類覆蓋“工廠”方法(@classmethod)時,問題就來了:
# Original method
@classmethod
def create(cls, request=None, **kwargs):
...
...
# Override attempt
@classmethod
def create(cls, request=None, **kwargs):
create_email = kwargs.pop("create_email", True)
user = kwargs.pop("user", None)
acc = Account.create(request, user, create_email)
x_account = cls(account, **kwargs)
x_account.save()
return x_account
我遇到的問題引發以下異常:
Django Version: 1.4.5
Exception Type: TypeError
Exception Value: create() takes at most 2 arguments (4 given)
Exception Location: /home/.../WebServices/models.py in create, line 27
...我無法理解,因為該方法的定義還包含2個隱式參數和** kwargs。 我究竟做錯了什么? 您可能會看到,我對Python沒有太多經驗。
您實際上並沒有使用任何關鍵字參數。
acc = Account.create(request, user=user, create_email=create_email)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.