我成功地运行了缺少的 django-allauth 教程中的示例以使用 facebook 登录,但是现在当我尝试从头开始安装 django-allauth 时出现此错误:
Given URL is not allowed by the Application configuration
Run Code Online (Sandbox Code Playgroud)
在 facebook 中,我的站点 URL 设置为http://127.0.0.1:8000/,这适用于示例但不适用于我的应用程序。错误来自哪里?
我也不明白 Django 管理中的“站点”字段:Home › Socialaccount › Social apps › AppName。默认情况下它设置为example.com,我不知道在这里设置什么,尽管它与example.com一起用于示例...
仅供参考,这里是示例的主要 urls.py
from django.conf.urls import patterns, include, url
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns(
'',
# prevent the extra are-you-sure-you-want-to-logout step on logout
(r'^accounts/logout/$', 'django.contrib.auth.views.logout', {'next_page': '/'}),
url(r'^', include('larb.urls')),
url(r'^accounts/', include('allauth.urls')),
url(r'^admin/', include(admin.site.urls)),
)
Run Code Online (Sandbox Code Playgroud)
和 urls.py 用于 larb:
from django.conf.urls import patterns, url …Run Code Online (Sandbox Code Playgroud) 我正在使用allauth进行身份验证,django消息在所有注册,登录等阶段都能正常工作.
但是,要避免第2步'你确定要退出吗?' 我已经覆盖了allauth视图:
url(r'^accounts/logout/$', 'django.contrib.auth.views.logout',{'next_page': '/', }),
Run Code Online (Sandbox Code Playgroud)
此技术工作正常,用户在单击"注销"后立即重定向到主页.
但是,通过这种方法,我无法再显示成功注销的消息.
任何人都可以使用消息框架和我当前的设置给我一个如何做到这一点的提示?
提前致谢,
我正在使用django-axes来限制对admin后端的登录尝试.但是,对于我的前端客户端通过django-allauth登录,我找不到任何机制来检测和防止登录失败.
使用allauth防止多次失败登录尝试的最佳方法是什么?有推荐的解决方案吗?我不太热衷于阻止来自特定IP的尝试,但是防止对单个用户名的多次尝试即"管理员"是好的.
提前致谢,
如果我在django设置中将我的allauth身份验证方法更改为电子邮件,我总是会收到以下错误:
The e-mail address and/or password you specified are not correct.
Run Code Online (Sandbox Code Playgroud)
即使电子邮件与数据库中的电子邮件匹配.
我使用以下设置在干净的django项目中尝试了这个:
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = "optional"
Run Code Online (Sandbox Code Playgroud)
我将电子邮件验证设置为可选,以消除错误来源,但无论我是否确认电子邮件地址,问题仍然存在.
我已设置allauth为每个新注册用户发送一封电子邮件,以便可以验证他们的电子邮件。现在,我使用email_backend,以便将电子邮件发送到终端,一切正常。
但是,现在我想对其进行全部设置,以便发送电子邮件,并且由于(可能)主机服务器上没有本地电子邮件服务器,而是例如使用gmail帐户发送验证电子邮件。这是可能吗?
我在我的django项目中使用Django-rest-auth(https://github.com/Tivix/django-rest-auth)进行登录和注册.我看到一个默认的注册表格如下:
目前,我可以使用电子邮件而不是用户名注册新用户.我的MySql数据库中的默认auth_user表包含以下列:(id,password,last_login,is_superuser,username,first_name,last_name,email,is_staff,is_active,date_joined)
我的settings.py:
INSTALLED_APPS = (
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.sites',
'rest_framework',
#Rest-auth
'rest_framework.authtoken',
'rest_auth',
#Rest-auth registration
'allauth',
'allauth.account',
'rest_auth.registration',
#Following is added to allow cross domain requests i.e. for serving requests those are coming from frontend app
'corsheaders',
'flights',
)
Run Code Online (Sandbox Code Playgroud)
我想修改我的注册表单,使其具有上面字段的名字和姓氏,这样当我注册一个新用户时,这两列也会填充first_name和last_name.目前我没有其他注册视图或任何自定义用户模型,我只是使用django-rest-auth提供的API端点.
我怎样才能做到这一点?
django django-rest-framework django-allauth django-rest-auth
我正在使用 django-allauth,每当我在登录表单中输入错误密码时,页面就会重新加载并且不会显示任何错误。这是我的 html 代码:
<form class="login" method="POST" action="{% url 'account_login' %}">
{% if form.errors %}
{% for field in form %}
{% for error in field.errors %}
<div class="alert alert-error">
<span><b> {{error}} </b><span>
</div>
{% endfor %}
{% endfor %}
{% endif %}
{% csrf_token %}
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
{{ form.login }}
<label class="mdl-textfield__label" for="id_login">Username/Email:</label>
</div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--floating-label">
{{ form.password }}
<label class="mdl-textfield__label" for="id_password">Password</label>
</div>
<label class="mdl-checkbox mdl-js-checkbox mdl-js-ripple-effect" for="id_remember">
{{form.remember}}<span class='mdl-checkbox__label 'align='left'>Remember me</span>
</label></br>
{% if …Run Code Online (Sandbox Code Playgroud) 设置
我正在使用 Django 1.8.15 和 django-allauth 0.28.0
描述
我想要做的很容易解释:如果用户通过社交媒体(facebook、google+ 或 twitter)登录,我想检索extra_datafromsociallogin以获取头像的 url 和其他信息以将其存储在我的Profile.一One-to-one relation到我的User模型。
我的方法
1)
首先,我添加了一个pre_social_login类似here的类,它在用户通过社交媒体登录后被调用。
模型.py
class SocialAdapter(DefaultSocialAccountAdapter):
def pre_social_login(self, request, sociallogin):
"""Get called after a social login. check for data and save what you want."""
user = User.objects.get(id=request.user.id) # Error: user not available
profile = Profile(user=user)
picture = sociallogin.account.extra_data.get('picture', None)
if picture:
# ... code to save picture to profile
Run Code Online (Sandbox Code Playgroud)
设置.py
SOCIALACCOUNT_ADAPTER = …Run Code Online (Sandbox Code Playgroud) 我已经使用django-allauth为我的 Web 应用程序实现了社交登录(provider-google)。我只想允许有限的域访问应用程序。以下是我对allauth的设置
设置.py
AUTHENTICATION_BACKENDS = (
'django.contrib.auth.backends.ModelBackend',
'allauth.account.auth_backends.AuthenticationBackend',
)
SOCIALACCOUNT_ADAPTER = 'mbaweb.socialaccount_adapter.NoNewUsersAccountAdapter'
LOGIN_REDIRECT_URL = "/"
SOCIALACCOUNT_PROVIDERS = {
'google': {
'SCOPE': [
'profile',
'email',
],
'AUTH_PARAMS': {
'access_type': 'online',
'hd': 'abc.com'
}
}
}
Run Code Online (Sandbox Code Playgroud)
通过使用“hd”参数,我只能允许域为“abc.com”的帐户。它限制所有其他域帐户。
但我的要求是允许应用程序的域列表
例如:- allowed_domains = ['abc.com', 'xyz.co.in', 'pqr.com']
有没有办法实现这一目标?
谢谢你的帮助。
使用带有django-rest-auth的Django REST Framework(DRF),我创建了一个带有一个额外字段的自定义用户模型。我的目标是使用django-rest-auth注册端点在一个请求中注册一个新用户,从而发送所有数据以创建一个新用户,包括多余字段的数据。
我正在使用AbstractUser,因为它似乎是推荐给初学者的,在初学者中,更高级的开发人员可以使用AbstractBaseUser。这也是为什么以下SO答案对于我想要实现的目标而言过于复杂的原因:链接此处。
我知道这个问题已经被问过多次了,但是答案并不完全是我想要的。对于像我这样的初学者来说,这是一件复杂的事情。
所以,我的问题是,任何人都可以解释如何实现我想要的吗?
我在用:
Django 2.1.4
django-allauth 0.38.0
django-rest-auth 0.9.3
djangorestframework 3.9.0
Run Code Online (Sandbox Code Playgroud)
这是到目前为止的代码:
使用本教程来获得此代码
settings.py:
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!gxred^*penrx*qlb=@p)p(vb!&6t78z4n!poz=zj+a0_9#sw1'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = [] …Run Code Online (Sandbox Code Playgroud) django django-rest-framework django-allauth django-rest-auth
django ×10
django-allauth ×10
python ×4
email ×2
facebook ×1
gmail ×1
google-oauth ×1
login ×1
oauth-2.0 ×1