自定义用户与django allauth [英] Custom users with django allauth
本文介绍了自定义用户与django allauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用带有django-allauth / social auth
的自定义用户在settings.py中,我有
I am trying to use a custom user with django-allauth/social auth In settings.py, I have
AUTHENTICATION_BACKENDS = (
# Needed to login by username in Django admin, regardless of `allauth`
"django.contrib.auth.backends.ModelBackend",
# `allauth` specific authentication methods, such as login by e-mail
"allauth.account.auth_backends.AuthenticationBackend",
)
SOCIALACCOUNT_PROVIDERS = \
{'facebook':
{'SCOPE': ['email', 'user_likes', 'user_status', 'user_about_me', 'basic_info', 'read_stream'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'oauth2',
'LOCALE_FUNC': 'path.to.callable',
'VERIFIED_EMAIL': False}}
LOGIN_REDIRECT_URL = '/results/'
AUTH_USER_MODEL = 'users.User'
在一个文件夹中项目文件夹中的用户,我有
adapter.py:
In a folder users within the project folder, I have adapter.py:
from django.conf import settings
from allauth.account.adapter import DefaultAccountAdapter
class MyAccountAdapter(DefaultAccountAdapter):
def get_login_redirect_url(self, request):
path = "/results/{username}/"
return path.format(username=request.user.username)
model.py:
from django.db import models
from django.contrib.auth.models import AbstractUser
class User(AbstractUser):
user_data = models.TextField(null=True)
当我尝试使用Facebook登录时,我被重定向到Facebook,但返回到该网站,我收到以下错误消息。
When I try to log in with facebook, I get redirected to facebook but returning to the site, I get the following error message
Django version 1.6.2
Exception Type: DoesNotExist
User matching query does not exist.
并在控制台中
"GET /results/facebook/login/? HTTP/1.1" 302 0
"GET /results/facebook/login/callback/XXX HTTP/1.1" 500
任何想法我做错了什么?
Any idea what I am doing wrong?
推荐答案
我想你可能正在通过电子邮件或反对者搜索用户名。尝试指定以下内容:
I think you might be searching for a username with an email or viceversa. Try specifying this:
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_AUTHENTICATION_METHOD = 'email'
这篇关于自定义用户与django allauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文