サイトで Facebook 認証が機能していますが、認証中にユーザーがプロファイル フォームに入力する必要があります。そのために認証パイプラインを使用しましたが、成功しませんでした。パイプラインは正常に呼び出されていますが、結果はエラーです。
彼の携帯電話番号が必要だとしましょう。Facebook からのものではないことを考慮してください。
考えてください:
models.py
from django.db import models
from django.contrib.auth.models import User
class Profile(models.Model):
user = models.OneToOneField(User)
mobile = models.IntegerField()
設定.py
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.mail.mail_validation',
'social.pipeline.user.create_user',
'social.pipeline.social_auth.associate_user',
'social.pipeline.social_auth.load_extra_data',
'social.pipeline.user.user_details',
'myapp.pipeline.fill_profile',
)
パイプライン.py
from myapp.models import Profile
from social.pipeline.partial import partial
@partial
def fill_profile(strategy, details, user=None, is_new=False, *args, **kwargs):
try:
if user and user.profile:
return
except:
return redirect('myapp.views.profile')
myapp/views.py
from django.shortcuts import render, redirect
from myapp.models import Perfil
def profile(request):
if request.method == 'POST':
profile = Perfil(user=request.user,mobile=request.POST.get('mobile'))
profile.save()
backend = request.session['partial_pipeline']['backend']
redirect('social:complete', backend=)
return render(request,'profile.html')
これprofile.html
は、「mobile」という名前の入力テキスト ボックスと送信ボタンを備えた単なるフォームです。
次に、次のエラーが表示されます。
Cannot assign "<SimpleLazyObject: <django.contrib.auth.models.AnonymousUser object at 0x03C2FB10>>": "Profile.user" must be a "User" instance.
auth_user テーブルのユーザーが既に存在するため、User インスタンスにアクセスできないのはなぜですか?
お願いします、これの何が問題なのですか?