2017-07-13 2 views
0

私はdjango-allauthとdjango 1.10を使って私の独自のカスタムアカウントアダプタを作成しましたので、パスワードの正規表現パターンを指定できます。django-allauth DefaultAccountAdapter clean_password()は予期しないキーワード引数 'user'を持っています

これは私のコードの抜粋です:

class MyAccountAdapter(DefaultAccountAdapter): 
    def clean_password(self, password): 
     if re.match(settings.ACCOUNT_PASSWORD_REGEX, password): 
      return password 
     else: 
      raise ValidationError("Password must be at least 8 characters long, contain one digit and one captalised alphabet") 

私は私のsettings.pyでこのクラスを使用するように指定しています(私はサインアップしようとすると

ACCOUNT_ADAPTER = 'app.adapters.MyAccountAdapter'

つまり、記入済みのフォームを提出すると)、次のエラーが表示されます。

TypeError at /accounts/signup/

clean_password() got an unexpected keyword argument 'user'

トレースバック:

File "/path/to/site-packages/django/core/handlers/exception.py" in inner 
    42.    response = get_response(request) 

File "/path/to/site-packages/django/core/handlers/base.py" in _get_response 
    187.     response = self.process_exception_by_middleware(e, request) 

File "/path/to/site-packages/django/core/handlers/base.py" in _get_response 
    185.     response = wrapped_callback(request, *callback_args, **callback_kwargs) 

File "/path/to/site-packages/django/views/generic/base.py" in view 
    68.    return self.dispatch(request, *args, **kwargs) 

File "/path/to/site-packages/django/utils/decorators.py" in _wrapper 
    67.    return bound_func(*args, **kwargs) 

File "/path/to/site-packages/django/views/decorators/debug.py" in sensitive_post_parameters_wrapper 
    76.    return view(request, *args, **kwargs) 

File "/path/to/site-packages/django/utils/decorators.py" in bound_func 
    63.     return func.__get__(self, type(self))(*args2, **kwargs2) 

File "/path/to/site-packages/allauth/account/views.py" in dispatch 
    205.   return super(SignupView, self).dispatch(request, *args, **kwargs) 

File "/path/to/site-packages/allauth/account/views.py" in dispatch 
    74.            **kwargs) 

File "/path/to/site-packages/allauth/account/views.py" in dispatch 
    183.               **kwargs) 

File "/path/to/site-packages/django/views/generic/base.py" in dispatch 
    88.   return handler(request, *args, **kwargs) 

File "/path/to/site-packages/allauth/account/views.py" in post 
    96.   if form.is_valid(): 

File "/path/to/site-packages/django/forms/forms.py" in is_valid 
    169.   return self.is_bound and not self.errors 

File "/path/to/site-packages/django/forms/forms.py" in errors 
    161.    self.full_clean() 

File "/path/to/site-packages/django/forms/forms.py" in full_clean 
    371.   self._clean_form() 

File "/path/to/site-packages/django/forms/forms.py" in _clean_form 
    398.    cleaned_data = self.clean() 

File "/path/to/site-packages/allauth/account/forms.py" in clean 
    363.      user=dummy_user) 

Exception Type: TypeError at /accounts/signup/ 
Exception Value: clean_password() got an unexpected keyword argument 'user' 

何この不可解なエラーの意味だ、と私はそれをどのように修正するのですか?

答えて

1

clean_passwordDefaultAccountAdapter実装を見てみましょう:

def clean_password(self, password, user=None): 
     """ 
     Validates a password. You can hook into this if you want to 
     restric the allowed password choices. 
     """ 

あなたはuserキーワードパラメータが欠落しています。

+0

Gah !,私は、関数のシグネチャが違っていたことを知りました。ソースコードを検索しました。 –

+0

投票に感謝しています:D – yorodm

関連する問題