認証パイプラインの最後に関数を追加したいのですが、この関数は、そのユーザーの「プロファイル」テーブルがあるかどうかを確認するためのもので、ない場合はテーブルを作成します。Profiles モデルは、ユーザーに関する追加情報を格納するテーブルです。
class Profiles(models.Model):
user = models.OneToOneField(User, unique=True, null=True)
description = models.CharField(max_length=250, blank=True, null=True)
points = models.SmallIntegerField(default=0)
posts_number = models.SmallIntegerField(default=0)
各ユーザーにはプロファイル テーブルが必要です。そこで、パイプラインの最後に関数を追加しました。
SOCIAL_AUTH_PIPELINE = (
'social.pipeline.social_auth.social_details',
'social.pipeline.social_auth.social_uid',
'social.pipeline.social_auth.auth_allowed',
'social.pipeline.social_auth.social_user',
'social.pipeline.user.get_username',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'app.utils.create_profile' #Custom pipeline
)
#utils.py
def create_profile(strategy, details, response, user, *args, **kwargs):
username = kwargs['details']['username']
user_object = User.objects.get(username=username)
if Profiles.ojects.filter(user=user_object).exists():
pass
else:
new_profile = Profiles(user=user_object)
new_profile.save()
return kwargs
エラーが発生します:
KeyError at /complete/facebook/
'details'
...
utils.py in create_profile
username = kwargs['details']['username']
私はpythonソーシャル認証を初めて使用していますが、明らかな何かが欠けているようです。どんな助けでも大歓迎です。