LoginSignup
4
2

More than 3 years have passed since last update.

"You have multiple authentication backends configured ..." への対処法(Django)

Last updated at Posted at 2019-11-25

この記事について

日本語で書かれている対処法がなかったので、書き残しておきます。

問題の発生

Djangoで作成していたアプリケーションにて、Userを作成してそのユーザーでログインした場合に以下のエラーが発生。

You have multiple authentication backends configured 
and therefore must provide the `backend` argument or 
set the `backend` attribute on the user.

原因

複数のAUTHENTICATION_BACKENDSを使用していたにも関わらず、ログインさせる処理でbackendの指定をしなかったため。

views.py
# ユーザー登録画面

# ログイン処理
login(self.request, user) # ここでエラー

※ソーシャルログイン機能を実装するためにdjango-allauthを使用していました。

settings.py

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend', # ID/pass
    'allauth.account.auth_backends.AuthenticationBackend', # ソーシャル
)

対処法

backendを指定した。

views.py
# ユーザー登録画面

# ログイン処理
login(self.request, user, backend='django.contrib.auth.backends.ModelBackend')

結果

解決しました。
backendを指定する必要があったんですね。

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2