标签: django-allauth

django-allauth:模块"accounts.forms"没有定义"SignupForm"类

我收到以下错误:

django.core.exceptions.ImproperlyConfigured:模块"accounts.forms"没有定义"SignupForm"类

settings.py

(...)

ACCOUNT_SIGNUP_FORM_CLASS = 'accounts.forms.SignupForm'

(...)
Run Code Online (Sandbox Code Playgroud)

账户/ forms.py

from allauth.account.forms import BaseSignupForm

class SignupForm(BaseSignupForm):

    def __init__(self, *args, **kwargs):
        self.sociallogin = kwargs.pop('sociallogin')
        user = self.sociallogin.account.user
        first_name = forms.CharField(label=_('First name'),
                                     max_length=30,
                                     min_length=2,
                                     widget=forms.TextInput(attrs={
                                         'placeholder':_('First name')}))
        last_name = forms.CharField(label=_('Last name'),
                                     max_length=30,
                                     min_length=2,
                                     widget=forms.TextInput(attrs={
                                         'placeholder':_('Last name')}))
        second_last_name = forms.CharField(label=_('Second last name'),
                                     max_length=30,
                                     empty='',
                                     widget=forms.TextInput(attrs={
                                         'placeholder':_('Second last name')}))
        # TODO: Should become more generic, not listing
        # a few fixed properties.
        initial = {'email': user_email(user) or '',
                   'username': user_username(user) or '',
                   'first_name': user_field(user, …
Run Code Online (Sandbox Code Playgroud)

django django-allauth

6
推荐指数
2
解决办法
1502
查看次数

Django Rest Framework + Django-Allauth 密码重置/恢复

我正在尝试使用 Django Rest Framework 和 Django-Allauth 创建密码恢复流程。

Django-Allauth 已经完成了我需要的一切,我的问题是我可以以编程方式调用 django-allauth 函数或从 DRF 接收我想要重置的电子邮件的视图,并继续正常的 allauth 流程的其余部分(例如创建临时令牌和发送电子邮件给客户?

如果其中一个应用程序正在做我需要的一切,我不认为必须重写所有代码。只需要一些关于如何“粘合”它们的帮助:)

python django password-recovery django-rest-framework django-allauth

6
推荐指数
2
解决办法
3009
查看次数

Django 1.7.1的迁移错误

在引入新应用程序(django-allauth)后执行迁移时出现错误.我不知道还有什么可以尝试以修复错误.我尝试了一些东西,但不幸的是它们似乎没有帮助.

运行manage.py migrate时:

File "D:\Python27\Lib\site-packages\django\db\migrations\state.py", line 71, 
in render raise     
InvalidBasesError("Cannot resolve bases for %r\nThis can happen if you are inheriting 
models from an app with migrations (e.g. contrib.auth)\n in an app with no migrations; 
see https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more" % 
new_unrendered_models)
django.db.migrations.state.InvalidBasesError: Cannot resolve bases for 
[<ModelState: 'blog.BlogPage'>, <ModelState: 'blog.BlogIndexPage'>]
This can happen if you are inheriting models from an app with migrations 
(e.g. contrib.auth) in an app with no migrations; see
https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies for more
Run Code Online (Sandbox Code Playgroud)

models.py

    from django.db …
Run Code Online (Sandbox Code Playgroud)

django django-allauth django-1.7 wagtail

6
推荐指数
2
解决办法
7561
查看次数

Django 1.8 - KeyError'请求'

我在这里有点傻眼,希望有人知道这个问题!

这是上下文:

{'form': <LoginForm bound=False, valid=Unknown, fields=(password;remember;login)>,
 'redirect_field_name': 'next',
 'redirect_field_value': None,
 'signup_url': u'/accounts/signup/',
 'site': <Site: brilliantactor.com>,
 u'view': <allauth.account.views.LoginView object at 0x10d7dead0>}
Run Code Online (Sandbox Code Playgroud)

请求对象看起来很正常

'<WSGIRequest\npath:/accounts/login/,\nGET:<QueryDict: {}>,\nPOST:<QueryDict: {}>,\nCOOKIES:{\'_ga\': \'GA1.1.908939259.1424705622\',\n \'csrftoken\': \'Ga0urMmd7AgBouS9KeH5V4EQNoyE8cqU\',\n [...]
Run Code Online (Sandbox Code Playgroud)

但是当读取以下行时:

context = make_context(context, request)
Run Code Online (Sandbox Code Playgroud)

输出上下文如下

[{'False': False, 'None': None, 'True': True}, 
 {}, 
 {'form': <LoginForm bound=False, valid=Unknown, fields=(password;remember;login)>, 
  'redirect_field_value': None, 
  'redirect_field_name': 'next', 
  'signup_url': u'/accounts/signup/', 
  'site': <Site: brilliantactor.com>, 
  u'view': <allauth.account.views.LoginView object at 0x10d7dead0>}]
Run Code Online (Sandbox Code Playgroud)

由于新的上下文对象没有"请求"键,因此一些模板标记失败,例如django-allauth


这是一个失败的例子:

https://github.com/pennersr/django-allauth/blob/master/allauth/socialaccount/templatetags/socialaccount.py#L20


我的TEMPLATE_CONTEXT_PROCESSORS:

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            join(BASE_DIR, 'templates'),
            # insert …
Run Code Online (Sandbox Code Playgroud)

python django django-templates django-allauth django-1.8

6
推荐指数
2
解决办法
3764
查看次数

如何在django admin的注册表中删除用户名字段?

使用 rest-framework 和 django-allauth 设置标志删除登录和注册所需的用户名:

#settings.py
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_UNIQUE_EMAIL = True
ACCOUNT_USERNAME_REQUIRED = False
Run Code Online (Sandbox Code Playgroud)

但我仍然看到管理员注册表中的用户名字段和用户列表中的用户名字段(没有用户名的用户为空)。

我怎样才能删除它?

python django admin django-rest-framework django-allauth

6
推荐指数
2
解决办法
5880
查看次数

django-allauth - 覆盖默认注册表单

我正在使用此代码(在forms.py中)为我的自定义注册表单:

class RegistrationForm(UserCreationForm):
    birth_date = forms.DateField(widget=extras.SelectDateWidget(years=BIRTH_DATE_YEARS))

    class Meta:
        model = get_user_model()
        fields = ('username', 'email', 'password1', 'password2', 'first_name', 'last_name', 'gender', 'birth_date', 'city', 'country')
Run Code Online (Sandbox Code Playgroud)

我当然ACCOUNT_SIGNUP_FORM_CLASS在settings.py中指定指向此表单,它显示我放入的字段.但是,它在提交时不起作用,即使我把signup方法永远不会被调用.我尝试了save但仍然是相同的 - 它引发了一个错误,我创建用户并将其保存到数据库时,我的一个自定义添加的字段是空白的.那么,实现这一目标的正确代码是什么?

django django-forms django-allauth

6
推荐指数
1
解决办法
8207
查看次数

如何判断用户的电子邮件地址是否已使用 Django、allauth、rest-auth 和自定义用户进行验证

我将 Django 2.0.10 与 rest-framework、rest-auth 和 allauth 一起使用。我有一个自定义用户模型。

我使用 allauth 视图进行了电子邮件验证。当用户注册时发送验证电子邮件。如果我单击电子邮件中的链接,我将被带到一个页面,其中有一个按钮可以单击以验证电子邮件。这一切都没有错误。但是我无法找出是什么这实际上。用户数据中的字段似乎没有改变。

我想要的行为是让用户能够注册和登录,但只能在他们验证电子邮件后才能向网站添加内容。

编辑:这篇文章给出了部分答案,但没有说明如何将验证状态保存为用户的属性,以便您在加载用户数据时可以在前端进行检查。

设置.py

# django rest auth
ACCOUNT_AUTHENTICATION_METHOD = 'email'
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
OLD_PASSWORD_FIELD_ENABLED = True
LOGOUT_ON_PASSWORD_CHANGE = False
ACCOUNT_EMAIL_VERIFICATION = 'optional'
Run Code Online (Sandbox Code Playgroud)

api/urls.py

from allauth.account.views import confirm_email

urlpatterns = [
    re_path(r'^rest-auth/registration/account-confirm-email/(?P<key>[-:\w]+)/$', confirm_email,
     name='account_confirm_email'),
...
]
Run Code Online (Sandbox Code Playgroud)

用户/模型.py

import uuid 

from django.contrib.auth.models import AbstractUser, UserManager
from django.db import models
from django.utils.http import int_to_base36

class CustomUserManager(UserManager):
    def get_by_natural_key(self, username):
        case_insensitive_username_field = '{}__iexact'.format(self.model.USERNAME_FIELD)
        return self.get(**{case_insensitive_username_field: username}) …
Run Code Online (Sandbox Code Playgroud)

django email-confirmation django-allauth

6
推荐指数
2
解决办法
4375
查看次数

Django allauth google OAuth redirect_uri_mismatch 错误

我正在为我的 Django 应用程序使用 Google OAuth(通过 allauth 包)

我已遵循所有标准配置步骤。在 Google 开发者控制台中,这是我所拥有的:

授权的 JavaScript 起源

https://example.com  
Run Code Online (Sandbox Code Playgroud)

授权的重定向 URI

https://example.com/accounts/google/login/callback/ - login fails
http://example.com/accounts/google/login/callback/ - login succeeds
Run Code Online (Sandbox Code Playgroud)

我观察到,如果我在授权的重定向 URI 中有一个https重定向 URL,它不允许登录,并且会因redirect_uri_mismatch错误而失败。如果我有一个http重定向 URL,则登录成功。

我需要做什么才能启用 https 重定向 URL?

django django-allauth

6
推荐指数
1
解决办法
1793
查看次数

如何使用 django-allauth 进行身份验证查找用户的 patreon 质押层

我正在使用 django-allauth 对用户进行身份验证(使用Patreon 的 API v1),它将一个 json 添加到数据库中,其中包含以下信息。如果用户的承诺与特定层级(或高于一层)相匹配,我想在网站上显示额外的内容。

{
  "attributes": {
    "about": null,
    "can_see_nsfw": true,
    "created": "2019-05-20T20:29:02.000+00:00",
    "default_country_code": null,
    "discord_id": null,
    "email": "admin@email.com",
    "facebook": null,
    "facebook_id": null,
    "first_name": "Adm",
    "full_name": "Adm Nsm",
    "gender": 0,
    "has_password": true,
    "image_url": "https://c8.patreon.com/2/200/21383296",
    "is_deleted": false,
    "is_email_verified": false,
    "is_nuked": false,
    "is_suspended": false,
    "last_name": "Nsm",
    "social_connections": {
      "deviantart": null,
      "discord": null,
      "facebook": null,
      "instagram": null,
      "reddit": null,
      "spotify": null,
      "twitch": null,
      "twitter": null,
      "youtube": null
    },
    "thumb_url": "https://c8.patreon.com/2/200/21383296",
    "twitch": null,
    "twitter": null,
    "url": "https://www.patreon.com/user?u=21383296",
    "vanity": …
Run Code Online (Sandbox Code Playgroud)

python api django django-allauth patreon

6
推荐指数
1
解决办法
1293
查看次数

使用 django-rest-auth 和 allauth 进行 Google 身份验证

我正在尝试为 Flutter 应用程序创建一个身份验证 API,该应用程序将使用谷歌身份验证注册/登录表单登录用户。我按照本教程来实现这一点。

到目前为止一切顺利,只是本教程基于 GitHub 登录而不是 Google。我设法让它一直工作到“连接”步骤。我能够code从重定向中获取 ,但是当我访问时,http://127.0.0.1:8000/auth/google/我看到它要求两个字段 ( access_token, code)。当我尝试只发布信息时,我收到以下错误:

 "non_field_errors": [
        "View is not defined, pass it as a context variable"
]
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

django python-3.x django-rest-framework django-allauth django-rest-auth

6
推荐指数
3
解决办法
1675
查看次数